diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-06-05 10:52:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-05 10:52:40 +0200 |
commit | 21c2c01ebed902c70763bb9319c3ec48c4cb5284 (patch) | |
tree | 82f01c418fc9abfb39aa370b3f3a6af820b10abb /ext/fetch/20_headers.js | |
parent | adf41edda12a26a84cb8b4252404aae2a9e7ae03 (diff) |
perf: optimize RegExp usage in JS (#19364)
Towards https://github.com/denoland/deno/issues/19330
Shows about 1% improvement in the HTTP benchmark.
Diffstat (limited to 'ext/fetch/20_headers.js')
-rw-r--r-- | ext/fetch/20_headers.js | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/ext/fetch/20_headers.js b/ext/fetch/20_headers.js index 89b9e1a2b..6d934a7c1 100644 --- a/ext/fetch/20_headers.js +++ b/ext/fetch/20_headers.js @@ -30,7 +30,7 @@ const { ArrayPrototypeFilter, ObjectEntries, ObjectHasOwn, - RegExpPrototypeTest, + RegExpPrototypeExec, SafeArrayIterator, SafeRegExp, Symbol, @@ -102,10 +102,10 @@ function appendHeader(headers, name, value) { value = normalizeHeaderValue(value); // 2. - if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) { + if (RegExpPrototypeExec(HTTP_TOKEN_CODE_POINT_RE, name) === null) { throw new TypeError("Header name is not valid."); } - if (RegExpPrototypeTest(ILLEGAL_VALUE_CHARS, value)) { + if (RegExpPrototypeExec(ILLEGAL_VALUE_CHARS, value) !== null) { throw new TypeError("Header value is not valid."); } @@ -282,7 +282,7 @@ class Headers { webidl.requiredArguments(arguments.length, 1, prefix); name = webidl.converters["ByteString"](name, prefix, "Argument 1"); - if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) { + if (RegExpPrototypeExec(HTTP_TOKEN_CODE_POINT_RE, name) === null) { throw new TypeError("Header name is not valid."); } if (this[_guard] == "immutable") { @@ -307,7 +307,7 @@ class Headers { webidl.requiredArguments(arguments.length, 1, prefix); name = webidl.converters["ByteString"](name, prefix, "Argument 1"); - if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) { + if (RegExpPrototypeExec(HTTP_TOKEN_CODE_POINT_RE, name) === null) { throw new TypeError("Header name is not valid."); } @@ -323,7 +323,7 @@ class Headers { webidl.requiredArguments(arguments.length, 1, prefix); name = webidl.converters["ByteString"](name, prefix, "Argument 1"); - if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) { + if (RegExpPrototypeExec(HTTP_TOKEN_CODE_POINT_RE, name) === null) { throw new TypeError("Header name is not valid."); } @@ -351,10 +351,10 @@ class Headers { value = normalizeHeaderValue(value); // 2. - if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, name)) { + if (RegExpPrototypeExec(HTTP_TOKEN_CODE_POINT_RE, name) === null) { throw new TypeError("Header name is not valid."); } - if (RegExpPrototypeTest(ILLEGAL_VALUE_CHARS, value)) { + if (RegExpPrototypeExec(ILLEGAL_VALUE_CHARS, value) !== null) { throw new TypeError("Header value is not valid."); } |