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 064f7c2

Browse filesBrowse files
mertcanaltinaduh95
authored andcommitted
src: use stack allocation in indexOf latin1 path
PR-URL: #62268 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Daniel Lemire <daniel@lemire.me>
1 parent 56dfeb0 commit 064f7c2
Copy full SHA for 064f7c2

2 files changed

+4-8Lines changed: 4 additions & 8 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎benchmark/buffers/buffer-indexof.js‎

Copy file name to clipboardExpand all lines: benchmark/buffers/buffer-indexof.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const searchStrings = [
1919

2020
const bench = common.createBenchmark(main, {
2121
search: searchStrings,
22-
encoding: ['undefined', 'utf8', 'ucs2'],
22+
encoding: ['undefined', 'utf8', 'ucs2', 'latin1'],
2323
type: ['buffer', 'string'],
2424
n: [5e4],
2525
}, {
Collapse file

‎src/node_buffer.cc‎

Copy file name to clipboardExpand all lines: src/node_buffer.cc
+3-7Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,23 +1051,19 @@ void IndexOfString(const FunctionCallbackInfo<Value>& args) {
10511051
offset,
10521052
is_forward);
10531053
} else if (enc == LATIN1) {
1054-
uint8_t* needle_data = node::UncheckedMalloc<uint8_t>(needle_length);
1055-
if (needle_data == nullptr) {
1056-
return args.GetReturnValue().Set(-1);
1057-
}
1054+
MaybeStackBuffer<uint8_t> needle_data(needle_length);
10581055
StringBytes::Write(isolate,
1059-
reinterpret_cast<char*>(needle_data),
1056+
reinterpret_cast<char*>(needle_data.out()),
10601057
needle_length,
10611058
needle,
10621059
enc);
10631060

10641061
result = nbytes::SearchString(reinterpret_cast<const uint8_t*>(haystack),
10651062
haystack_length,
1066-
needle_data,
1063+
needle_data.out(),
10671064
needle_length,
10681065
offset,
10691066
is_forward);
1070-
free(needle_data);
10711067
}
10721068

10731069
args.GetReturnValue().Set(

0 commit comments

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