summaryrefslogtreecommitdiff
path: root/ext/webidl/00_webidl.js
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-06-10 00:45:56 +0200
committerGitHub <noreply@github.com>2023-06-09 22:45:56 +0000
commit848cda619ec5de6e8bd03783c35ef726824be01c (patch)
tree073be3c88694ea7c7eed1f64793759dbc853fe38 /ext/webidl/00_webidl.js
parentf99a849a5f2de9fb1162ab41a566174e3d54612e (diff)
perf: optimize ByteString checks, hoist server rid getter (#19452)
Further improves preact SSR and express benches by about 2k RPS. Ref https://github.com/denoland/deno/issues/19451
Diffstat (limited to 'ext/webidl/00_webidl.js')
-rw-r--r--ext/webidl/00_webidl.js15
1 files changed, 11 insertions, 4 deletions
diff --git a/ext/webidl/00_webidl.js b/ext/webidl/00_webidl.js
index ca1c7c606..9454dc392 100644
--- a/ext/webidl/00_webidl.js
+++ b/ext/webidl/00_webidl.js
@@ -59,7 +59,6 @@ const {
ReflectHas,
ReflectOwnKeys,
RegExpPrototypeTest,
- RegExpPrototypeExec,
SafeRegExp,
SafeSet,
SetPrototypeEntries,
@@ -403,11 +402,19 @@ converters.DOMString = function (V, prefix, context, opts = {}) {
return String(V);
};
-// deno-lint-ignore no-control-regex
-const IS_BYTE_STRING = new SafeRegExp(/^[\x00-\xFF]*$/);
+function isByteString(input) {
+ for (let i = 0; i < input.length; i++) {
+ if (StringPrototypeCharCodeAt(input, i) > 255) {
+ // If a character code is greater than 255, it means the string is not a byte string.
+ return false;
+ }
+ }
+ return true;
+}
+
converters.ByteString = (V, prefix, context, opts) => {
const x = converters.DOMString(V, prefix, context, opts);
- if (RegExpPrototypeExec(IS_BYTE_STRING, x) === null) {
+ if (!isByteString(x)) {
throw makeException(
TypeError,
"is not a valid ByteString",