Skip to content

Commit

Permalink
url: call ada::can_parse directly
Browse files Browse the repository at this point in the history
PR-URL: #47919
Reviewed-By: Matthew Aitken <maitken033380023@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
anonrig authored and targos committed May 30, 2023
1 parent f564b03 commit ebb6536
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,32 +125,25 @@ void BindingData::CanParse(const FunctionCallbackInfo<Value>& 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<ada::url_aggregator> base;
ada::url_aggregator* base_pointer = nullptr;
std::string_view input_view = input.ToStringView();

bool can_parse{};
if (args[1]->IsString()) {
base = ada::parse<ada::url_aggregator>(
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<ada::url_aggregator>(input.ToStringView(), base_pointer);

args.GetReturnValue().Set(out.has_value());
args.GetReturnValue().Set(can_parse);
}

bool BindingData::FastCanParse(Local<Value> receiver,
const FastOneByteString& input) {
std::string_view input_view(input.data, input.length);

auto output = ada::parse<ada::url_aggregator>(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));
Expand Down

0 comments on commit ebb6536

Please sign in to comment.