@@ -37,15 +37,17 @@ using v8::Value; |
37 | 37 | namespace { |
38 | 38 |
|
39 | 39 | // 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. |
44 | 46 | ada::result<ada::url_aggregator> ParseUrlFromV8String( |
45 | 47 | Isolate* isolate, |
46 | 48 | Local<String> input, |
47 | 49 | const ada::url_aggregator* base_url, |
48 | | - bool* reuse_input) { |
| 50 | + bool* reuse_input = nullptr) { |
49 | 51 | { |
50 | 52 | String::ValueView view(isolate, input); |
51 | 53 | if (view.is_one_byte()) { |
@@ -54,12 +56,14 @@ ada::result<ada::url_aggregator> ParseUrlFromV8String( |
54 | 56 | if (simdutf::validate_ascii(data, length)) [[likely]] { |
55 | 57 | const std::string_view input_view(data, length); |
56 | 58 | 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 | + } |
58 | 62 | return out; |
59 | 63 | } |
60 | 64 | } |
61 | 65 | } |
62 | | - *reuse_input = false; |
| 66 | + if (reuse_input != nullptr) *reuse_input = false; |
63 | 67 | Utf8Value utf8(isolate, input); |
64 | 68 | return ada::parse<ada::url_aggregator>(utf8.ToStringView(), base_url); |
65 | 69 | } |
@@ -430,9 +434,7 @@ void BindingData::Parse(const FunctionCallbackInfo<Value>& args) { |
430 | 434 | ada::result<ada::url_aggregator> base; |
431 | 435 | ada::url_aggregator* base_pointer = nullptr; |
432 | 436 | 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); |
436 | 438 | if (!base) { |
437 | 439 | if (raise_exception) { |
438 | 440 | Utf8Value input(isolate, input_string); |
@@ -497,9 +499,7 @@ void BindingData::Update(const FunctionCallbackInfo<Value>& args) { |
497 | 499 | // A serialized URL is not always reparsable: the IDNA encoder can emit a |
498 | 500 | // host label that the decoder rejects. Fail the update instead of crashing. |
499 | 501 | // 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); |
503 | 503 | if (!out) { |
504 | 504 | return args.GetReturnValue().Set(false); |
505 | 505 | } |
|