Skip to content

Commit caa85b0

Browse files
committed
url: skip unused href reuse comparison
Callers that never reuse the original V8 string (base URL parse and setters) now omit reuse_input so ParseUrlFromV8String does not compare href against the input. Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com> Assisted-by: Cursor Co-authored-by: Yagiz Nizipli <anonrig@users.noreply.github.com>
1 parent 47af16c commit caa85b0

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

src/node_url.cc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ using v8::Value;
3737
namespace {
3838

3939
// Parse a V8 string as a URL. One-byte ASCII inputs are parsed in place
40-
// without allocating a UTF-8 copy. `reuse_input` is set when the serialized
41-
// href is identical to that ASCII input so the caller can return the original
42-
// V8 string. Non-ASCII inputs are never reused: UTF-8 conversion may replace
43-
// unpaired surrogates, so the original string may not match href.
40+
// without allocating a UTF-8 copy. When `reuse_input` is non-null it is set
41+
// if the serialized href is identical to that ASCII input so the caller can
42+
// return the original V8 string. Omit it when the caller will not reuse the
43+
// input, to skip the O(n) href comparison. Non-ASCII inputs are never reused:
44+
// UTF-8 conversion may replace unpaired surrogates, so the original string
45+
// may not match href.
4446
ada::result<ada::url_aggregator> ParseUrlFromV8String(
4547
Isolate* isolate,
4648
Local<String> input,
4749
const ada::url_aggregator* base_url,
48-
bool* reuse_input) {
50+
bool* reuse_input = nullptr) {
4951
{
5052
String::ValueView view(isolate, input);
5153
if (view.is_one_byte()) {
@@ -54,12 +56,14 @@ ada::result<ada::url_aggregator> ParseUrlFromV8String(
5456
if (simdutf::validate_ascii(data, length)) [[likely]] {
5557
const std::string_view input_view(data, length);
5658
auto out = ada::parse<ada::url_aggregator>(input_view, base_url);
57-
*reuse_input = out.has_value() && out->get_href() == input_view;
59+
if (reuse_input != nullptr) {
60+
*reuse_input = out.has_value() && out->get_href() == input_view;
61+
}
5862
return out;
5963
}
6064
}
6165
}
62-
*reuse_input = false;
66+
if (reuse_input != nullptr) *reuse_input = false;
6367
Utf8Value utf8(isolate, input);
6468
return ada::parse<ada::url_aggregator>(utf8.ToStringView(), base_url);
6569
}
@@ -430,9 +434,7 @@ void BindingData::Parse(const FunctionCallbackInfo<Value>& args) {
430434
ada::result<ada::url_aggregator> base;
431435
ada::url_aggregator* base_pointer = nullptr;
432436
if (args[1]->IsString()) {
433-
bool unused_reuse = false;
434-
base = ParseUrlFromV8String(
435-
isolate, args[1].As<String>(), nullptr, &unused_reuse);
437+
base = ParseUrlFromV8String(isolate, args[1].As<String>(), nullptr);
436438
if (!base) {
437439
if (raise_exception) {
438440
Utf8Value input(isolate, input_string);
@@ -497,9 +499,7 @@ void BindingData::Update(const FunctionCallbackInfo<Value>& args) {
497499
// A serialized URL is not always reparsable: the IDNA encoder can emit a
498500
// host label that the decoder rejects. Fail the update instead of crashing.
499501
// Existing hrefs are typically already-serialized ASCII, so parse in place.
500-
bool unused_reuse = false;
501-
auto out = ParseUrlFromV8String(
502-
isolate, args[0].As<String>(), nullptr, &unused_reuse);
502+
auto out = ParseUrlFromV8String(isolate, args[0].As<String>(), nullptr);
503503
if (!out) {
504504
return args.GetReturnValue().Set(false);
505505
}

0 commit comments

Comments
 (0)