perf(webidl/ByteString): 3x faster ASCII check
String,
StringFromCodePoint,
StringPrototypeCharCodeAt,
- StringPrototypeCodePointAt,
Symbol,
SymbolIterator,
SymbolToStringTag,
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;
};
