From ebb65367754dee4463828993ad8ede550b9a26bf Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Thu, 18 May 2023 13:49:02 -0400 Subject: [PATCH] url: call `ada::can_parse` directly PR-URL: https://github.com/nodejs/node/pull/47919 Reviewed-By: Matthew Aitken Reviewed-By: James M Snell Reviewed-By: Darshan Sen --- src/node_url.cc | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/node_url.cc b/src/node_url.cc index 078e155fc49374..c5e1be2131fd23 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -125,32 +125,25 @@ void BindingData::CanParse(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); HandleScope handle_scope(env->isolate()); - Context::Scope context_scope(env->context()); Utf8Value input(env->isolate(), args[0]); - ada::result base; - ada::url_aggregator* base_pointer = nullptr; + std::string_view input_view = input.ToStringView(); + + bool can_parse{}; if (args[1]->IsString()) { - base = ada::parse( - Utf8Value(env->isolate(), args[1]).ToString()); - if (!base) { - return args.GetReturnValue().Set(false); - } - base_pointer = &base.value(); + Utf8Value base(env->isolate(), args[1]); + std::string_view base_view = base.ToStringView(); + can_parse = ada::can_parse(input_view, &base_view); + } else { + can_parse = ada::can_parse(input_view); } - auto out = - ada::parse(input.ToStringView(), base_pointer); - args.GetReturnValue().Set(out.has_value()); + args.GetReturnValue().Set(can_parse); } bool BindingData::FastCanParse(Local receiver, const FastOneByteString& input) { - std::string_view input_view(input.data, input.length); - - auto output = ada::parse(input_view); - - return output.has_value(); + return ada::can_parse(std::string_view(input.data, input.length)); } CFunction BindingData::fast_can_parse_(CFunction::Make(FastCanParse));