Skip to content

Commit

Permalink
url: reduce unnecessary string copies
Browse files Browse the repository at this point in the history
PR-URL: #53628
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Daniel Lemire <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Marco Ippolito <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
anonrig authored and marco-ippolito committed Aug 19, 2024
1 parent e71aa7e commit 7fc45f5
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ void BindingData::Deserialize(v8::Local<v8::Context> context,

void BindingData::DomainToASCII(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK_GE(args.Length(), 1);
CHECK_GE(args.Length(), 1); // input
CHECK(args[0]->IsString());

std::string input = Utf8Value(env->isolate(), args[0]).ToString();
if (input.empty()) {
return args.GetReturnValue().Set(String::Empty(env->isolate()));
Utf8Value input(env->isolate(), args[0]);
if (input.ToStringView().empty()) {
return args.GetReturnValue().SetEmptyString();
}

// It is important to have an initial value that contains a special scheme.
// Since it will change the implementation of `set_hostname` according to URL
// spec.
auto out = ada::parse<ada::url>("ws://x");
DCHECK(out);
if (!out->set_hostname(input)) {
if (!out->set_hostname(input.ToStringView())) {
return args.GetReturnValue().Set(String::Empty(env->isolate()));
}
std::string host = out->get_hostname();
Expand All @@ -98,20 +98,20 @@ void BindingData::DomainToASCII(const FunctionCallbackInfo<Value>& args) {

void BindingData::DomainToUnicode(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
CHECK_GE(args.Length(), 1);
CHECK_GE(args.Length(), 1); // input
CHECK(args[0]->IsString());

std::string input = Utf8Value(env->isolate(), args[0]).ToString();
if (input.empty()) {
return args.GetReturnValue().Set(String::Empty(env->isolate()));
Utf8Value input(env->isolate(), args[0]);
if (input.ToStringView().empty()) {
return args.GetReturnValue().SetEmptyString();
}

// It is important to have an initial value that contains a special scheme.
// Since it will change the implementation of `set_hostname` according to URL
// spec.
auto out = ada::parse<ada::url>("ws://x");
DCHECK(out);
if (!out->set_hostname(input)) {
if (!out->set_hostname(input.ToStringView())) {
return args.GetReturnValue().Set(String::Empty(env->isolate()));
}
std::string result = ada::unicode::to_unicode(out->get_hostname());
Expand Down

0 comments on commit 7fc45f5

Please sign in to comment.