From 5144f6ba26584773ef011367bd70e276daeaab1a Mon Sep 17 00:00:00 2001 From: Gino Notto Date: Fri, 12 Oct 2018 11:34:32 -0700 Subject: [PATCH 1/2] change macro to fn Change base64_encoded_size and unbase64 to inline functions. The base64_encoded_size is a constexpr to be used in function declarations. --- src/base64.h | 10 ++++++---- src/inspector_socket.cc | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/base64.h b/src/base64.h index a19d11f71c65f5..aedec375eba550 100644 --- a/src/base64.h +++ b/src/base64.h @@ -10,8 +10,9 @@ namespace node { //// Base 64 //// -#define base64_encoded_size(size) ((size + 2 - ((size + 2) % 3)) / 3 * 4) - +static inline constexpr size_t base64_encoded_size(size_t size) { + return ((size + 2 - ((size + 2) % 3)) / 3 * 4); +} // Doesn't check for padding at the end. Can be 1-2 bytes over. static inline size_t base64_decoded_size_fast(size_t size) { @@ -48,8 +49,9 @@ size_t base64_decoded_size(const TypeName* src, size_t size) { extern const int8_t unbase64_table[256]; -#define unbase64(x) \ - static_cast(unbase64_table[static_cast(x)]) +inline static int8_t unbase64(uint8_t x) { + return unbase64_table[x]; +} template diff --git a/src/inspector_socket.cc b/src/inspector_socket.cc index dc36359b5c927c..540b427a775b3e 100644 --- a/src/inspector_socket.cc +++ b/src/inspector_socket.cc @@ -143,6 +143,7 @@ enum ws_decode_result { FRAME_OK, FRAME_INCOMPLETE, FRAME_CLOSE, FRAME_ERROR }; + static void generate_accept_string(const std::string& client_key, char (*buffer)[ACCEPT_KEY_LENGTH]) { // Magic string from websockets spec. From b9fbd3712943ba4b1b97fcb72472ca7afca9b77e Mon Sep 17 00:00:00 2001 From: Gino Notto Date: Fri, 12 Oct 2018 11:48:17 -0700 Subject: [PATCH 2/2] remove unneeded whitespace --- src/inspector_socket.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/inspector_socket.cc b/src/inspector_socket.cc index 540b427a775b3e..dc36359b5c927c 100644 --- a/src/inspector_socket.cc +++ b/src/inspector_socket.cc @@ -143,7 +143,6 @@ enum ws_decode_result { FRAME_OK, FRAME_INCOMPLETE, FRAME_CLOSE, FRAME_ERROR }; - static void generate_accept_string(const std::string& client_key, char (*buffer)[ACCEPT_KEY_LENGTH]) { // Magic string from websockets spec.