1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

perf(fetch): optimize normalizeMethod() (#10154)

This commit is contained in:
Aaron O'Mullan 2021-04-13 02:45:57 +02:00 committed by GitHub
parent 2eafbf2b98
commit 9f26e639dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -922,22 +922,36 @@
});
}
/**
* @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;
}