mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
perf(webidl/ByteString): 3x faster ASCII check (#12230)
This commit is contained in:
parent
7f2976b3e6
commit
1749e79f97
1 changed files with 4 additions and 7 deletions
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue