Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 67fcb6b

Browse filesBrowse files
lemiretargos
authored andcommitted
buffer: even faster atob
PR-URL: #52443 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent a589de0 commit 67fcb6b
Copy full SHA for 67fcb6b

File tree

Expand file treeCollapse file tree

1 file changed

+18
-6
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+18
-6
lines changed
Open diff view settings
Collapse file

‎src/node_buffer.cc‎

Copy file name to clipboardExpand all lines: src/node_buffer.cc
+18-6Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,19 +1286,31 @@ static void Atob(const FunctionCallbackInfo<Value>& args) {
12861286
auto ext = input->GetExternalOneByteStringResource();
12871287
size_t expected_length =
12881288
simdutf::maximal_binary_length_from_base64(ext->data(), ext->length());
1289-
buffer.AllocateSufficientStorage(expected_length + 1);
1290-
buffer.SetLengthAndZeroTerminate(expected_length);
1289+
buffer.AllocateSufficientStorage(expected_length);
1290+
buffer.SetLength(expected_length);
12911291
result = simdutf::base64_to_binary(
12921292
ext->data(), ext->length(), buffer.out(), simdutf::base64_default);
1293+
} else if (input->IsOneByte()) {
1294+
MaybeStackBuffer<uint8_t> stack_buf(input->Length());
1295+
input->WriteOneByte(args.GetIsolate(),
1296+
stack_buf.out(),
1297+
0,
1298+
input->Length(),
1299+
String::NO_NULL_TERMINATION);
1300+
const char* data = reinterpret_cast<const char*>(*stack_buf);
1301+
size_t expected_length =
1302+
simdutf::maximal_binary_length_from_base64(data, input->Length());
1303+
buffer.AllocateSufficientStorage(expected_length);
1304+
buffer.SetLength(expected_length);
1305+
result = simdutf::base64_to_binary(data, input->Length(), buffer.out());
12931306
} else { // 16-bit case
12941307
String::Value value(env->isolate(), input);
12951308
auto data = reinterpret_cast<const char16_t*>(*value);
12961309
size_t expected_length =
12971310
simdutf::maximal_binary_length_from_base64(data, value.length());
1298-
buffer.AllocateSufficientStorage(expected_length + 1);
1299-
buffer.SetLengthAndZeroTerminate(expected_length);
1300-
result = simdutf::base64_to_binary(
1301-
data, value.length(), buffer.out(), simdutf::base64_default);
1311+
buffer.AllocateSufficientStorage(expected_length);
1312+
buffer.SetLength(expected_length);
1313+
result = simdutf::base64_to_binary(data, value.length(), buffer.out());
13021314
}
13031315

13041316
if (result.error == simdutf::error_code::SUCCESS) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.