Skip to content

Commit

Permalink
url: improve performance by removing host
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Feb 14, 2023
1 parent 632af80 commit 2694506
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
8 changes: 4 additions & 4 deletions lib/internal/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ class URLContext {
href = '';
origin = '';
protocol = '';
host = '';
hostname = '';
pathname = '';
search = '';
Expand Down Expand Up @@ -626,14 +625,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 @@ -716,7 +714,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
23 changes: 10 additions & 13 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,20 @@ enum url_update_action {
kHref = 9,
};

void SetArgs(Environment* env, Local<Value> argv[12], const ada::result& url) {
void SetArgs(Environment* env, Local<Value> argv[11], const ada::result& url) {
Isolate* isolate = env->isolate();
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 2694506

Please sign in to comment.