perf: optimize RegExp usage in JS (#19364)

Towards https://github.com/denoland/deno/issues/19330

Shows about 1% improvement in the HTTP benchmark.
This commit is contained in:
Bartek Iwańczuk 2023-06-05 10:52:40 +02:00 committed by GitHub
parent adf41edda1
commit 21c2c01ebe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 16 deletions

View file

@ -36,7 +36,7 @@ const {
ArrayPrototypeSplice,
ObjectKeys,
ObjectPrototypeIsPrototypeOf,
RegExpPrototypeTest,
RegExpPrototypeExec,
StringPrototypeStartsWith,
Symbol,
SymbolFor,
@ -227,7 +227,7 @@ function validateAndNormalizeMethod(m) {
}
// Regular path
if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, m)) {
if (RegExpPrototypeExec(HTTP_TOKEN_CODE_POINT_RE, m) === null) {
throw new TypeError("Method is not valid.");
}
const upperCase = byteUpperCase(m);