summaryrefslogtreecommitdiff
path: root/op_crates/fetch
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-04-13 02:45:57 +0200
committerGitHub <noreply@github.com>2021-04-13 02:45:57 +0200
commit9f26e639dd6ddc9416bfd4d12b87efdac2699b1d (patch)
treec388947115972c3e10cfaae8c756dc4ee25f4529 /op_crates/fetch
parent2eafbf2b98e56ef992ba0ea47886e97c9567886e (diff)
perf(fetch): optimize normalizeMethod() (#10154)
Diffstat (limited to 'op_crates/fetch')
-rw-r--r--op_crates/fetch/26_fetch.js30
1 files changed, 22 insertions, 8 deletions
diff --git a/op_crates/fetch/26_fetch.js b/op_crates/fetch/26_fetch.js
index 8dc7c2056..0bcd8f85c 100644
--- a/op_crates/fetch/26_fetch.js
+++ b/op_crates/fetch/26_fetch.js
@@ -924,20 +924,34 @@
/**
* @param {string} m
+ * @returns {boolean}
+ */
+ function isKnownMethod(m) {
+ return (
+ m === "DELETE" ||
+ m === "GET" ||
+ m === "HEAD" ||
+ m === "OPTIONS" ||
+ m === "POST" ||
+ m === "PUT"
+ );
+ }
+
+ /**
+ * @param {string} m
* @returns {string}
*/
function normalizeMethod(m) {
+ // Fast path for already valid methods
+ if (isKnownMethod(m)) {
+ return m;
+ }
+ // Normalize lower case (slowpath and should be avoided ...)
const u = byteUpperCase(m);
- if (
- u === "DELETE" ||
- u === "GET" ||
- u === "HEAD" ||
- u === "OPTIONS" ||
- u === "POST" ||
- u === "PUT"
- ) {
+ if (isKnownMethod(u)) {
return u;
}
+ // Otherwise passthrough
return m;
}