Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url: reduce unnecessary string copies #53628

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,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 @@ -99,20 +99,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
Loading