diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2021-08-18 23:21:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-18 23:21:33 +0200 |
commit | bf0bacbc0ec3bd7ef1c55ddc01ef44b2ce593d4a (patch) | |
tree | b0a39f028e22e3a7270bb711d146f87baeeece33 /ext/url/00_url.js | |
parent | e55454613cd5ad04c427a49c4287e60b1563c32e (diff) |
perf(ext/url): cleanup and optimize url parsing op args (#11763)
This splits the previous `op_url_parse` into:
- `op_url_parse`: parses a href with an optional base
- `op_url_reparse`: reparses a href with a modifier
This is a cleaner separation of concerns and it allows us to optimize & simplify args passed. Resulting in a 25% reduction in call overhead (~5000ns/call => ~3700ns/call in url_ops bench on my M1 Air)
Diffstat (limited to 'ext/url/00_url.js')
-rw-r--r-- | ext/url/00_url.js | 75 |
1 files changed, 28 insertions, 47 deletions
diff --git a/ext/url/00_url.js b/ext/url/00_url.js index f3c12d0c2..33235f934 100644 --- a/ext/url/00_url.js +++ b/ext/url/00_url.js @@ -29,6 +29,22 @@ const _list = Symbol("list"); const _urlObject = Symbol("url object"); + // WARNING: must match rust code's UrlSetter::* + const SET_HASH = 1; + const SET_HOST = 2; + const SET_HOSTNAME = 3; + const SET_PASSWORD = 4; + const SET_PATHNAME = 5; + const SET_PORT = 6; + const SET_PROTOCOL = 7; + const SET_SEARCH = 8; + const SET_USERNAME = 9; + + // Helper function + function opUrlReparse(href, setter, value) { + return core.opSync("op_url_reparse", href, [setter, value]); + } + class URLSearchParams { [_list]; [_urlObject] = null; @@ -78,11 +94,7 @@ if (url === null) { return; } - const parts = core.opSync("op_url_parse", { - href: url.href, - setSearch: this.toString(), - }); - url[_url] = parts; + url[_url] = opUrlReparse(url.href, SET_SEARCH, this.toString()); } /** @@ -277,9 +289,7 @@ }); } this[webidl.brand] = webidl.brand; - - const parts = core.opSync("op_url_parse", { href: url, baseHref: base }); - this[_url] = parts; + this[_url] = core.opSync("op_url_parse", url, base); } [SymbolFor("Deno.privateCustomInspect")](inspect) { @@ -326,10 +336,7 @@ context: "Argument 1", }); try { - this[_url] = core.opSync("op_url_parse", { - href: this[_url].href, - setHash: value, - }); + this[_url] = opUrlReparse(this[_url].href, SET_HASH, value); } catch { /* pass */ } @@ -351,10 +358,7 @@ context: "Argument 1", }); try { - this[_url] = core.opSync("op_url_parse", { - href: this[_url].href, - setHost: value, - }); + this[_url] = opUrlReparse(this[_url].href, SET_HOST, value); } catch { /* pass */ } @@ -376,10 +380,7 @@ context: "Argument 1", }); try { - this[_url] = core.opSync("op_url_parse", { - href: this[_url].href, - setHostname: value, - }); + this[_url] = opUrlReparse(this[_url].href, SET_HOSTNAME, value); } catch { /* pass */ } @@ -400,9 +401,7 @@ prefix, context: "Argument 1", }); - this[_url] = core.opSync("op_url_parse", { - href: value, - }); + this[_url] = core.opSync("op_url_parse", value); this.#updateSearchParams(); } @@ -428,10 +427,7 @@ context: "Argument 1", }); try { - this[_url] = core.opSync("op_url_parse", { - href: this[_url].href, - setPassword: value, - }); + this[_url] = opUrlReparse(this[_url].href, SET_PASSWORD, value); } catch { /* pass */ } @@ -453,10 +449,7 @@ context: "Argument 1", }); try { - this[_url] = core.opSync("op_url_parse", { - href: this[_url].href, - setPathname: value, - }); + this[_url] = opUrlReparse(this[_url].href, SET_PATHNAME, value); } catch { /* pass */ } @@ -478,10 +471,7 @@ context: "Argument 1", }); try { - this[_url] = core.opSync("op_url_parse", { - href: this[_url].href, - setPort: value, - }); + this[_url] = opUrlReparse(this[_url].href, SET_PORT, value); } catch { /* pass */ } @@ -503,10 +493,7 @@ context: "Argument 1", }); try { - this[_url] = core.opSync("op_url_parse", { - href: this[_url].href, - setProtocol: value, - }); + this[_url] = opUrlReparse(this[_url].href, SET_PROTOCOL, value); } catch { /* pass */ } @@ -528,10 +515,7 @@ context: "Argument 1", }); try { - this[_url] = core.opSync("op_url_parse", { - href: this[_url].href, - setSearch: value, - }); + this[_url] = opUrlReparse(this[_url].href, SET_SEARCH, value); this.#updateSearchParams(); } catch { /* pass */ @@ -554,10 +538,7 @@ context: "Argument 1", }); try { - this[_url] = core.opSync("op_url_parse", { - href: this[_url].href, - setUsername: value, - }); + this[_url] = opUrlReparse(this[_url].href, SET_USERNAME, value); } catch { /* pass */ } |