From 22f555a499e09011651b9e262f41405e5c6aada7 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Thu, 11 Jul 2024 16:13:52 -0400 Subject: [PATCH] url: reduce unnecessary string copies PR-URL: https://github.com/nodejs/node/pull/53628 Reviewed-By: Richard Lau Reviewed-By: Daniel Lemire Reviewed-By: Luigi Pinca Reviewed-By: Benjamin Gruenbaum Reviewed-By: Marco Ippolito Reviewed-By: James M Snell --- src/node_url.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/node_url.cc b/src/node_url.cc index c94537dd714e74..6cd81b73a40587 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -76,12 +76,12 @@ void BindingData::Deserialize(v8::Local context, void BindingData::DomainToASCII(const FunctionCallbackInfo& 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. @@ -89,7 +89,7 @@ void BindingData::DomainToASCII(const FunctionCallbackInfo& args) { // spec. auto out = ada::parse("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(); @@ -99,12 +99,12 @@ void BindingData::DomainToASCII(const FunctionCallbackInfo& args) { void BindingData::DomainToUnicode(const FunctionCallbackInfo& 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. @@ -112,7 +112,7 @@ void BindingData::DomainToUnicode(const FunctionCallbackInfo& args) { // spec. auto out = ada::parse("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());