summaryrefslogtreecommitdiff
path: root/ext/webidl/00_webidl.js
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-09-26 20:40:37 +0200
committerGitHub <noreply@github.com>2021-09-26 20:40:37 +0200
commit1749e79f97af29262c88c66c3a834e8eff4197c6 (patch)
tree817f8260382749e8f1f4374221ccaf150eda99b8 /ext/webidl/00_webidl.js
parent7f2976b3e6e227bb031cff4dcc5a55f51e0b1656 (diff)
perf(webidl/ByteString): 3x faster ASCII check (#12230)
Diffstat (limited to 'ext/webidl/00_webidl.js')
-rw-r--r--ext/webidl/00_webidl.js11
1 files changed, 4 insertions, 7 deletions
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;
};