Skip to content

Commit fd7fc99

Browse files
Gino Nottojasnell
Gino Notto
authored andcommitted
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: #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>
1 parent d778f9e commit fd7fc99

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/base64.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
namespace node {
1212
//// Base 64 ////
13-
#define base64_encoded_size(size) ((size + 2 - ((size + 2) % 3)) / 3 * 4)
14-
13+
static inline constexpr size_t base64_encoded_size(size_t size) {
14+
return ((size + 2 - ((size + 2) % 3)) / 3 * 4);
15+
}
1516

1617
// Doesn't check for padding at the end. Can be 1-2 bytes over.
1718
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) {
4849
extern const int8_t unbase64_table[256];
4950

5051

51-
#define unbase64(x) \
52-
static_cast<uint8_t>(unbase64_table[static_cast<uint8_t>(x)])
52+
inline static int8_t unbase64(uint8_t x) {
53+
return unbase64_table[x];
54+
}
5355

5456

5557
template <typename TypeName>

0 commit comments

Comments
 (0)