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/web/01_mimesniff.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ext/web') diff --git a/ext/web/01_mimesniff.js b/ext/web/01_mimesniff.js index ad89f33cd..7d402e080 100644 --- a/ext/web/01_mimesniff.js +++ b/ext/web/01_mimesniff.js @@ -13,6 +13,7 @@ const { MapPrototypeHas, MapPrototypeSet, RegExpPrototypeTest, + RegExpPrototypeExec, SafeMap, SafeMapIterator, StringPrototypeReplaceAll, @@ -197,7 +198,7 @@ function serializeMimeType(mimeType) { for (const param of new SafeMapIterator(mimeType.parameters)) { serialization += `;${param[0]}=`; let value = param[1]; - if (!RegExpPrototypeTest(HTTP_TOKEN_CODE_POINT_RE, value)) { + if (RegExpPrototypeExec(HTTP_TOKEN_CODE_POINT_RE, value) === null) { value = StringPrototypeReplaceAll(value, "\\", "\\\\"); value = StringPrototypeReplaceAll(value, '"', '\\"'); value = `"${value}"`; -- cgit v1.2.3