Skip to content

Commit

Permalink
url: improve performance by removing host
Browse files Browse the repository at this point in the history
PR-URL: #46547
Backport-PR-URL: #47435
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
anonrig authored and danielleadams committed Apr 12, 2023
1 parent 0c67a7a commit 01b6525
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
8 changes: 4 additions & 4 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ class URLContext {
href = '';
origin = '';
protocol = '';
host = '';
hostname = '';
pathname = '';
search = '';
Expand Down Expand Up @@ -634,14 +633,13 @@ class URL {
return constructHref(this[context], options);
}

#onParseComplete = (href, origin, protocol, host, hostname, pathname,
#onParseComplete = (href, origin, protocol, hostname, pathname,
search, username, password, port, hash, hasHost,
hasOpaquePath) => {
const ctx = this[context];
ctx.href = href;
ctx.origin = origin;
ctx.protocol = protocol;
ctx.host = host;
ctx.hostname = hostname;
ctx.pathname = pathname;
ctx.search = search;
Expand Down Expand Up @@ -724,7 +722,9 @@ class URL {
get host() {
if (!isURLThis(this))
throw new ERR_INVALID_THIS('URL');
return this[context].host;
const port = this[context].port;
const suffix = port.length > 0 ? `:${port}` : '';
return this[context].hostname + suffix;
}

set host(value) {
Expand Down
21 changes: 9 additions & 12 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,15 @@ void SetArgs(Environment* env, Local<Value> argv[12], const ada::result& url) {
argv[0] = Utf8String(isolate, url->get_href());
argv[1] = Utf8String(isolate, url->get_origin());
argv[2] = Utf8String(isolate, url->get_protocol());
argv[3] = Utf8String(isolate, url->get_host());
argv[4] = Utf8String(isolate, url->get_hostname());
argv[5] = Utf8String(isolate, url->get_pathname());
argv[6] = Utf8String(isolate, url->get_search());
argv[7] = Utf8String(isolate, url->get_username());
argv[8] = Utf8String(isolate, url->get_password());
argv[9] = Utf8String(isolate, url->get_port());
argv[10] = Utf8String(isolate, url->get_hash());
argv[11] = Boolean::New(isolate, url->host.has_value());
argv[12] = Boolean::New(isolate, url->has_opaque_path);
argv[3] = Utf8String(isolate, url->get_hostname());
argv[4] = Utf8String(isolate, url->get_pathname());
argv[5] = Utf8String(isolate, url->get_search());
argv[6] = Utf8String(isolate, url->get_username());
argv[7] = Utf8String(isolate, url->get_password());
argv[8] = Utf8String(isolate, url->get_port());
argv[9] = Utf8String(isolate, url->get_hash());
argv[10] = Boolean::New(isolate, url->host.has_value());
argv[11] = Boolean::New(isolate, url->has_opaque_path);
}

void Parse(const FunctionCallbackInfo<Value>& args) {
Expand Down Expand Up @@ -108,7 +107,6 @@ void Parse(const FunctionCallbackInfo<Value>& args) {
undef,
undef,
undef,
undef,
};
SetArgs(env, argv, out);
USE(success_callback_->Call(
Expand Down Expand Up @@ -259,7 +257,6 @@ void UpdateUrl(const FunctionCallbackInfo<Value>& args) {
undef,
undef,
undef,
undef,
};
SetArgs(env, argv, out);
USE(success_callback_->Call(
Expand Down
1 change: 0 additions & 1 deletion test/parallel/test-whatwg-url-custom-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ assert.strictEqual(
href: 'https://username:password@host.name:8080/path/name/?que=ry#hash',
origin: 'https://host.name:8080',
protocol: 'https:',
host: 'host.name:8080',
hostname: 'host.name',
pathname: '/path/name/',
search: '?que=ry',
Expand Down

0 comments on commit 01b6525

Please sign in to comment.