diff options
author | Gino Notto <gnotto@bloomberg.net> | 2018-10-12 21:34:32 +0300 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2018-10-15 16:38:36 +0300 |
commit | 17c35a6297e1b8b97bb0cddc1c69cc573fb7aed0 (patch) | |
tree | 52291205862c57241772f755b6f9add10051cab2 /src/base64.h | |
parent | febb7656e3dc336952319f91b02efbc898b9c65a (diff) |
src: 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.
PR-URL: https://github.com/nodejs/node/pull/23603
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Diffstat (limited to 'src/base64.h')
-rw-r--r-- | src/base64.h | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/base64.h b/src/base64.h index a19d11f71c6..aedec375eba 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<uint8_t>(unbase64_table[static_cast<uint8_t>(x)]) +inline static int8_t unbase64(uint8_t x) { + return unbase64_table[x]; +} template <typename TypeName> |