From 21c2c01ebed902c70763bb9319c3ec48c4cb5284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 5 Jun 2023 10:52:40 +0200 Subject: perf: optimize RegExp usage in JS (#19364) Towards https://github.com/denoland/deno/issues/19330 Shows about 1% improvement in the HTTP benchmark. --- ext/fetch/23_request.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ext/fetch/23_request.js') diff --git a/ext/fetch/23_request.js b/ext/fetch/23_request.js index 4c46ebe75..daf77a834 100644 --- a/ext/fetch/23_request.js +++ b/ext/fetch/23_request.js @@ -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); -- cgit v1.2.3