Skip to content
Merged
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
src: use stack allocation in indexOf latin1 path
  • Loading branch information
mertcanaltin committed Mar 15, 2026
commit a95b66f349244aefecc21a96d55418a63e2bf884
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-indexof.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const searchStrings = [

const bench = common.createBenchmark(main, {
search: searchStrings,
encoding: ['undefined', 'utf8', 'ucs2'],
encoding: ['undefined', 'utf8', 'ucs2', 'latin1'],
type: ['buffer', 'string'],
n: [5e4],
}, {
Expand Down
10 changes: 3 additions & 7 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1051,23 +1051,19 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) {
offset,
is_forward);
} else if (enc == LATIN1) {
uint8_t* needle_data = node::UncheckedMalloc<uint8_t>(needle_length);
if (needle_data == nullptr) {
return args.GetReturnValue().Set(-1);
}
MaybeStackBuffer<uint8_t> needle_data(needle_length);
Comment thread
mertcanaltin marked this conversation as resolved.
StringBytes::Write(isolate,
reinterpret_cast<char*>(needle_data),
reinterpret_cast<char*>(needle_data.out()),
needle_length,
needle,
enc);

result = nbytes::SearchString(reinterpret_cast<const uint8_t*>(haystack),
haystack_length,
needle_data,
needle_data.out(),
needle_length,
offset,
is_forward);
free(needle_data);
}

args.GetReturnValue().Set(
Expand Down
Loading