summaryrefslogtreecommitdiff
path: root/ext/url/00_url.js
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-08-19 13:41:47 +0200
committerGitHub <noreply@github.com>2021-08-19 13:41:47 +0200
commit37c983d1e8e83fd2b381028d37f6358df1fa4513 (patch)
tree46e0349c5cbfe0b25bcae789d2194211b49ce781 /ext/url/00_url.js
parent0d83afd93973cf4051aa73a0a05a78b451763d33 (diff)
perf(ext/url): optimize UrlParts op serialization (#11765)
Diffstat (limited to 'ext/url/00_url.js')
-rw-r--r--ext/url/00_url.js40
1 files changed, 36 insertions, 4 deletions
diff --git a/ext/url/00_url.js b/ext/url/00_url.js
index 33235f934..805a61329 100644
--- a/ext/url/00_url.js
+++ b/ext/url/00_url.js
@@ -40,9 +40,41 @@
const SET_SEARCH = 8;
const SET_USERNAME = 9;
- // Helper function
+ // Helper functions
function opUrlReparse(href, setter, value) {
- return core.opSync("op_url_reparse", href, [setter, value]);
+ return _urlParts(core.opSync("op_url_reparse", href, [setter, value]));
+ }
+ function opUrlParse(href, maybeBase) {
+ return _urlParts(core.opSync("op_url_parse", href, maybeBase));
+ }
+ function _urlParts(internalParts) {
+ // WARNING: must match UrlParts serialization rust's url_result()
+ const {
+ 0: href,
+ 1: hash,
+ 2: host,
+ 3: hostname,
+ 4: origin,
+ 5: password,
+ 6: pathname,
+ 7: port,
+ 8: protocol,
+ 9: search,
+ 10: username,
+ } = internalParts.split("\n");
+ return {
+ href,
+ hash,
+ host,
+ hostname,
+ origin,
+ password,
+ pathname,
+ port,
+ protocol,
+ search,
+ username,
+ };
}
class URLSearchParams {
@@ -289,7 +321,7 @@
});
}
this[webidl.brand] = webidl.brand;
- this[_url] = core.opSync("op_url_parse", url, base);
+ this[_url] = opUrlParse(url, base);
}
[SymbolFor("Deno.privateCustomInspect")](inspect) {
@@ -401,7 +433,7 @@
prefix,
context: "Argument 1",
});
- this[_url] = core.opSync("op_url_parse", value);
+ this[_url] = opUrlParse(value);
this.#updateSearchParams();
}