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/webidl/00_webidl.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ext/webidl') diff --git a/ext/webidl/00_webidl.js b/ext/webidl/00_webidl.js index dfaa774e2..ca1c7c606 100644 --- a/ext/webidl/00_webidl.js +++ b/ext/webidl/00_webidl.js @@ -59,6 +59,7 @@ const { ReflectHas, ReflectOwnKeys, RegExpPrototypeTest, + RegExpPrototypeExec, SafeRegExp, SafeSet, SetPrototypeEntries, @@ -406,7 +407,7 @@ converters.DOMString = function (V, prefix, context, opts = {}) { const IS_BYTE_STRING = new SafeRegExp(/^[\x00-\xFF]*$/); converters.ByteString = (V, prefix, context, opts) => { const x = converters.DOMString(V, prefix, context, opts); - if (!RegExpPrototypeTest(IS_BYTE_STRING, x)) { + if (RegExpPrototypeExec(IS_BYTE_STRING, x) === null) { throw makeException( TypeError, "is not a valid ByteString", -- cgit v1.2.3