From 7fc45f5e3ff194312617982c16a156e6af69de08 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 94510aa1904a00..dccc7c16c22d78 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -75,12 +75,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. @@ -88,7 +88,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(); @@ -98,12 +98,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. @@ -111,7 +111,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());