mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
perf(ext/url): optimize UrlParts op serialization (#11765)
This commit is contained in:
parent
0d83afd939
commit
37c983d1e8
2 changed files with 69 additions and 32 deletions
|
@ -40,9 +40,41 @@
|
||||||
const SET_SEARCH = 8;
|
const SET_SEARCH = 8;
|
||||||
const SET_USERNAME = 9;
|
const SET_USERNAME = 9;
|
||||||
|
|
||||||
// Helper function
|
// Helper functions
|
||||||
function opUrlReparse(href, setter, value) {
|
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 {
|
class URLSearchParams {
|
||||||
|
@ -289,7 +321,7 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this[webidl.brand] = webidl.brand;
|
this[webidl.brand] = webidl.brand;
|
||||||
this[_url] = core.opSync("op_url_parse", url, base);
|
this[_url] = opUrlParse(url, base);
|
||||||
}
|
}
|
||||||
|
|
||||||
[SymbolFor("Deno.privateCustomInspect")](inspect) {
|
[SymbolFor("Deno.privateCustomInspect")](inspect) {
|
||||||
|
@ -401,7 +433,7 @@
|
||||||
prefix,
|
prefix,
|
||||||
context: "Argument 1",
|
context: "Argument 1",
|
||||||
});
|
});
|
||||||
this[_url] = core.opSync("op_url_parse", value);
|
this[_url] = opUrlParse(value);
|
||||||
this.#updateSearchParams();
|
this.#updateSearchParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ use deno_core::url::quirks;
|
||||||
use deno_core::url::Url;
|
use deno_core::url::Url;
|
||||||
use deno_core::Extension;
|
use deno_core::Extension;
|
||||||
use deno_core::ZeroCopyBuf;
|
use deno_core::ZeroCopyBuf;
|
||||||
use serde::Serialize;
|
|
||||||
use std::panic::catch_unwind;
|
use std::panic::catch_unwind;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
@ -36,20 +35,23 @@ pub fn init() -> Extension {
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
// UrlParts is a \n joined string of the following parts:
|
||||||
pub struct UrlParts {
|
// #[derive(Serialize)]
|
||||||
href: String,
|
// pub struct UrlParts {
|
||||||
hash: String,
|
// href: String,
|
||||||
host: String,
|
// hash: String,
|
||||||
hostname: String,
|
// host: String,
|
||||||
origin: String,
|
// hostname: String,
|
||||||
password: String,
|
// origin: String,
|
||||||
pathname: String,
|
// password: String,
|
||||||
port: String,
|
// pathname: String,
|
||||||
protocol: String,
|
// port: String,
|
||||||
search: String,
|
// protocol: String,
|
||||||
username: String,
|
// search: String,
|
||||||
}
|
// username: String,
|
||||||
|
// }
|
||||||
|
// TODO: implement cleaner & faster serialization
|
||||||
|
type UrlParts = String;
|
||||||
|
|
||||||
/// Parse `UrlParseArgs::href` with an optional `UrlParseArgs::base_href`, or an
|
/// Parse `UrlParseArgs::href` with an optional `UrlParseArgs::base_href`, or an
|
||||||
/// optional part to "set" after parsing. Return `UrlParts`.
|
/// optional part to "set" after parsing. Return `UrlParts`.
|
||||||
|
@ -137,19 +139,22 @@ fn url_result(
|
||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(UrlParts {
|
Ok(
|
||||||
href: quirks::href(&url).to_string(),
|
[
|
||||||
hash: quirks::hash(&url).to_string(),
|
quirks::href(&url),
|
||||||
host: quirks::host(&url).to_string(),
|
quirks::hash(&url),
|
||||||
hostname: quirks::hostname(&url).to_string(),
|
quirks::host(&url),
|
||||||
origin: quirks::origin(&url),
|
quirks::hostname(&url),
|
||||||
password: quirks::password(&url).to_string(),
|
&quirks::origin(&url),
|
||||||
pathname: quirks::pathname(&url).to_string(),
|
quirks::password(&url),
|
||||||
port: quirks::port(&url).to_string(),
|
quirks::pathname(&url),
|
||||||
protocol: quirks::protocol(&url).to_string(),
|
quirks::port(&url),
|
||||||
search: quirks::search(&url).to_string(),
|
quirks::protocol(&url),
|
||||||
username: username.to_string(),
|
quirks::search(&url),
|
||||||
})
|
username,
|
||||||
|
]
|
||||||
|
.join("\n"),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn op_url_parse_search_params(
|
pub fn op_url_parse_search_params(
|
||||||
|
|
Loading…
Add table
Reference in a new issue