Skip to content

Commit

Permalink
src: change macro to fn
Browse files Browse the repository at this point in the history
Change base64_encoded_size and unbase64 to inline functions. The
base64_encoded_size is a constexpr to be used in function declarations.

PR-URL: #23603
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
  • Loading branch information
Gino Notto authored and MylesBorins committed Nov 29, 2018
1 parent 591af98 commit e7bf838
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit e7bf838

Please sign in to comment.