Skip to content

Commit

Permalink
src: remove base64_select_table and base64_table
Browse files Browse the repository at this point in the history
node::base64_encode() uses ::base64_encode() when the mode is
Base64Mode::NORMAL, so base64_select_table is only ever called for
Base64Mode::URL and thus only ever returns base64_table_url, but never
base64_table.

Also move base64_table_url into base64-inl.h.

PR-URL: nodejs#44425
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
  • Loading branch information
tniessen authored and Fyko committed Sep 15, 2022
1 parent c77d1e9 commit d945bd0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
6 changes: 5 additions & 1 deletion src/base64-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

namespace node {

static constexpr char base64_table_url[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789-_";

extern const int8_t unbase64_table[256];


Expand Down Expand Up @@ -144,7 +148,7 @@ inline size_t base64_encode(const char* src,
unsigned k;
unsigned n;

const char* table = base64_select_table(mode);
const char* table = base64_table_url;

i = 0;
k = 0;
Expand Down
16 changes: 0 additions & 16 deletions src/base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,6 @@ enum class Base64Mode {
URL
};

static constexpr char base64_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";

static constexpr char base64_table_url[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789-_";

static inline const char* base64_select_table(Base64Mode mode) {
switch (mode) {
case Base64Mode::NORMAL: return base64_table;
case Base64Mode::URL: return base64_table_url;
default: UNREACHABLE();
}
}

static inline constexpr size_t base64_encoded_size(
size_t size,
Base64Mode mode = Base64Mode::NORMAL) {
Expand Down

0 comments on commit d945bd0

Please sign in to comment.