Skip to content

Commit 3937415

Browse files
committed
speed up base64 decode character lookup
1 parent 4be16cd commit 3937415

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

Base64.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,10 @@ inline void a4_to_a3(unsigned char * a3, unsigned char * a4) {
122122
}
123123

124124
inline unsigned char b64_lookup(char c) {
125-
int i;
126-
for(i = 0; i < 64; i++) {
127-
if(b64_alphabet[i] == c) {
128-
return i;
129-
}
130-
}
131-
125+
if(c >='A' && c <='Z') return c - 'A';
126+
if(c >='a' && c <='z') return c - 71;
127+
if(c >='0' && c <='9') return c + 4;
128+
if(c == '+') return 62;
129+
if(c == '/') return 63;
132130
return -1;
133131
}

0 commit comments

Comments
 (0)