perf(webidl/ByteString): 3x faster ASCII check (#12230)

This commit is contained in:
Aaron O'Mullan 2021-09-26 20:40:37 +02:00 committed by GitHub
parent 7f2976b3e6
commit 1749e79f97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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) {
if (!RegExpPrototypeTest(IS_BYTE_STRING, x)) {
throw makeException(TypeError, "is not a valid ByteString", opts);
}
}
return x;
};