Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# name -> (function name, keyword arguments, input preparation)
OPERATIONS = {
"b64encode": ("b64encode", {}, lambda raw: raw),
"b64encode(altchars)": ("b64encode", {"altchars": b"*!"}, lambda raw: raw),
"b64decode": ("b64decode", {}, base64.b64encode),
"b64decode(validate=True)": ("b64decode", {"validate": True}, base64.b64encode),
"urlsafe_b64encode": ("urlsafe_b64encode", {}, lambda raw: raw),
Expand Down
10 changes: 5 additions & 5 deletions src/fastpybase64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ PyObject *encode_with_altchars(const InputView &input, const char altchars[2]) {
}
char *out = PyBytes_AS_STRING(result);
Py_ssize_t length = PyBytes_GET_SIZE(result);
const char plus = altchars[0];
const char slash = altchars[1];
// Store every byte so the compiler can vectorize the substitution.
for (Py_ssize_t i = 0; i < length; i++) {
if (out[i] == '+') {
out[i] = altchars[0];
} else if (out[i] == '/') {
out[i] = altchars[1];
}
const char c = out[i];
out[i] = c == '+' ? plus : (c == '/' ? slash : c);
}
return result;
}
Expand Down