Skip to content

Commit 2c6548a

Browse files
anonrigaduh95
authored andcommitted
url: reduce unnecessary string copies
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]>
1 parent aa7df95 commit 2c6548a

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/node_url.cc

+10-10
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,20 @@ void BindingData::Deserialize(v8::Local<v8::Context> context,
7676

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

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

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

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

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

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

0 commit comments

Comments
 (0)