mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 20:29:11 +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,
|
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) {
|
throw makeException(TypeError, "is not a valid ByteString", opts);
|
||||||
if (c > 255) {
|
|
||||||
throw makeException(TypeError, "is not a valid ByteString", opts);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue