Skip to content

Commit 01b6525

Browse files
anonrigdanielleadams
authored andcommitted
url: improve performance by removing host
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>
1 parent 0c67a7a commit 01b6525

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

lib/internal/url.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ class URLContext {
145145
href = '';
146146
origin = '';
147147
protocol = '';
148-
host = '';
149148
hostname = '';
150149
pathname = '';
151150
search = '';
@@ -634,14 +633,13 @@ class URL {
634633
return constructHref(this[context], options);
635634
}
636635

637-
#onParseComplete = (href, origin, protocol, host, hostname, pathname,
636+
#onParseComplete = (href, origin, protocol, hostname, pathname,
638637
search, username, password, port, hash, hasHost,
639638
hasOpaquePath) => {
640639
const ctx = this[context];
641640
ctx.href = href;
642641
ctx.origin = origin;
643642
ctx.protocol = protocol;
644-
ctx.host = host;
645643
ctx.hostname = hostname;
646644
ctx.pathname = pathname;
647645
ctx.search = search;
@@ -724,7 +722,9 @@ class URL {
724722
get host() {
725723
if (!isURLThis(this))
726724
throw new ERR_INVALID_THIS('URL');
727-
return this[context].host;
725+
const port = this[context].port;
726+
const suffix = port.length > 0 ? `:${port}` : '';
727+
return this[context].hostname + suffix;
728728
}
729729

730730
set host(value) {

src/node_url.cc

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,15 @@ void SetArgs(Environment* env, Local<Value> argv[12], const ada::result& url) {
5252
argv[0] = Utf8String(isolate, url->get_href());
5353
argv[1] = Utf8String(isolate, url->get_origin());
5454
argv[2] = Utf8String(isolate, url->get_protocol());
55-
argv[3] = Utf8String(isolate, url->get_host());
56-
argv[4] = Utf8String(isolate, url->get_hostname());
57-
argv[5] = Utf8String(isolate, url->get_pathname());
58-
argv[6] = Utf8String(isolate, url->get_search());
59-
argv[7] = Utf8String(isolate, url->get_username());
60-
argv[8] = Utf8String(isolate, url->get_password());
61-
argv[9] = Utf8String(isolate, url->get_port());
62-
argv[10] = Utf8String(isolate, url->get_hash());
63-
argv[11] = Boolean::New(isolate, url->host.has_value());
64-
argv[12] = Boolean::New(isolate, url->has_opaque_path);
55+
argv[3] = Utf8String(isolate, url->get_hostname());
56+
argv[4] = Utf8String(isolate, url->get_pathname());
57+
argv[5] = Utf8String(isolate, url->get_search());
58+
argv[6] = Utf8String(isolate, url->get_username());
59+
argv[7] = Utf8String(isolate, url->get_password());
60+
argv[8] = Utf8String(isolate, url->get_port());
61+
argv[9] = Utf8String(isolate, url->get_hash());
62+
argv[10] = Boolean::New(isolate, url->host.has_value());
63+
argv[11] = Boolean::New(isolate, url->has_opaque_path);
6564
}
6665

6766
void Parse(const FunctionCallbackInfo<Value>& args) {
@@ -108,7 +107,6 @@ void Parse(const FunctionCallbackInfo<Value>& args) {
108107
undef,
109108
undef,
110109
undef,
111-
undef,
112110
};
113111
SetArgs(env, argv, out);
114112
USE(success_callback_->Call(
@@ -259,7 +257,6 @@ void UpdateUrl(const FunctionCallbackInfo<Value>& args) {
259257
undef,
260258
undef,
261259
undef,
262-
undef,
263260
};
264261
SetArgs(env, argv, out);
265262
USE(success_callback_->Call(

test/parallel/test-whatwg-url-custom-inspect.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ assert.strictEqual(
4949
href: 'https://username:password@host.name:8080/path/name/?que=ry#hash',
5050
origin: 'https://host.name:8080',
5151
protocol: 'https:',
52-
host: 'host.name:8080',
5352
hostname: 'host.name',
5453
pathname: '/path/name/',
5554
search: '?que=ry',

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy