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, String,
StringFromCodePoint, StringFromCodePoint,
StringPrototypeCharCodeAt, StringPrototypeCharCodeAt,
StringPrototypeCodePointAt,
Symbol, Symbol,
SymbolIterator, SymbolIterator,
SymbolToStringTag, SymbolToStringTag,
@ -375,15 +374,13 @@
return String(V); return String(V);
}; };
// deno-lint-ignore no-control-regex
const IS_BYTE_STRING = /^[\x00-\xFF]*$/;
converters.ByteString = (V, opts) => { converters.ByteString = (V, opts) => {
const x = converters.DOMString(V, opts); const x = converters.DOMString(V, opts);
let c; if (!RegExpPrototypeTest(IS_BYTE_STRING, x)) {
for (let i = 0; (c = StringPrototypeCodePointAt(x, i)) !== undefined; ++i) {
if (c > 255) {
throw makeException(TypeError, "is not a valid ByteString", opts); throw makeException(TypeError, "is not a valid ByteString", opts);
} }
}
return x; return x;
}; };