summaryrefslogtreecommitdiff
path: root/ext/url/lib.rs
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/lib.rs
parent0d83afd93973cf4051aa73a0a05a78b451763d33 (diff)
perf(ext/url): optimize UrlParts op serialization (#11765)
Diffstat (limited to 'ext/url/lib.rs')
-rw-r--r--ext/url/lib.rs61
1 files changed, 33 insertions, 28 deletions
diff --git a/ext/url/lib.rs b/ext/url/lib.rs
index 25ecc1358..d8987c816 100644
--- a/ext/url/lib.rs
+++ b/ext/url/lib.rs
@@ -11,7 +11,6 @@ use deno_core::url::quirks;
use deno_core::url::Url;
use deno_core::Extension;
use deno_core::ZeroCopyBuf;
-use serde::Serialize;
use std::panic::catch_unwind;
use std::path::PathBuf;
@@ -36,20 +35,23 @@ pub fn init() -> Extension {
.build()
}
-#[derive(Serialize)]
-pub struct UrlParts {
- href: String,
- hash: String,
- host: String,
- hostname: String,
- origin: String,
- password: String,
- pathname: String,
- port: String,
- protocol: String,
- search: String,
- username: String,
-}
+// UrlParts is a \n joined string of the following parts:
+// #[derive(Serialize)]
+// pub struct UrlParts {
+// href: String,
+// hash: String,
+// host: String,
+// hostname: String,
+// origin: String,
+// password: String,
+// pathname: String,
+// port: String,
+// protocol: String,
+// search: String,
+// username: String,
+// }
+// TODO: implement cleaner & faster serialization
+type UrlParts = String;
/// Parse `UrlParseArgs::href` with an optional `UrlParseArgs::base_href`, or an
/// optional part to "set" after parsing. Return `UrlParts`.
@@ -137,19 +139,22 @@ fn url_result(
))
})?;
- Ok(UrlParts {
- href: quirks::href(&url).to_string(),
- hash: quirks::hash(&url).to_string(),
- host: quirks::host(&url).to_string(),
- hostname: quirks::hostname(&url).to_string(),
- origin: quirks::origin(&url),
- password: quirks::password(&url).to_string(),
- pathname: quirks::pathname(&url).to_string(),
- port: quirks::port(&url).to_string(),
- protocol: quirks::protocol(&url).to_string(),
- search: quirks::search(&url).to_string(),
- username: username.to_string(),
- })
+ Ok(
+ [
+ quirks::href(&url),
+ quirks::hash(&url),
+ quirks::host(&url),
+ quirks::hostname(&url),
+ &quirks::origin(&url),
+ quirks::password(&url),
+ quirks::pathname(&url),
+ quirks::port(&url),
+ quirks::protocol(&url),
+ quirks::search(&url),
+ username,
+ ]
+ .join("\n"),
+ )
}
pub fn op_url_parse_search_params(