From 1749e79f97af29262c88c66c3a834e8eff4197c6 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Sun, 26 Sep 2021 20:40:37 +0200 Subject: perf(webidl/ByteString): 3x faster ASCII check (#12230) --- ext/webidl/00_webidl.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'ext/webidl/00_webidl.js') diff --git a/ext/webidl/00_webidl.js b/ext/webidl/00_webidl.js index 0b8d5c03d..88384406a 100644 --- a/ext/webidl/00_webidl.js +++ b/ext/webidl/00_webidl.js @@ -62,7 +62,6 @@ String, StringFromCodePoint, StringPrototypeCharCodeAt, - StringPrototypeCodePointAt, Symbol, SymbolIterator, SymbolToStringTag, @@ -375,15 +374,13 @@ return String(V); }; + // deno-lint-ignore no-control-regex + const IS_BYTE_STRING = /^[\x00-\xFF]*$/; converters.ByteString = (V, opts) => { const x = converters.DOMString(V, opts); - let c; - for (let i = 0; (c = StringPrototypeCodePointAt(x, i)) !== undefined; ++i) { - if (c > 255) { - throw makeException(TypeError, "is not a valid ByteString", opts); - } + if (!RegExpPrototypeTest(IS_BYTE_STRING, x)) { + throw makeException(TypeError, "is not a valid ByteString", opts); } - return x; }; -- cgit v1.2.3