mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
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
This commit is contained in:
parent
f7cb0b44e3
commit
a0a7a65cc3
2 changed files with 12 additions and 5 deletions
|
@ -682,8 +682,8 @@ function serveHttpOn(context, callback) {
|
||||||
|
|
||||||
// Run the server
|
// Run the server
|
||||||
const finished = (async () => {
|
const finished = (async () => {
|
||||||
|
const rid = context.serverRid;
|
||||||
while (true) {
|
while (true) {
|
||||||
const rid = context.serverRid;
|
|
||||||
let req;
|
let req;
|
||||||
try {
|
try {
|
||||||
// Attempt to pull as many requests out of the queue as possible before awaiting. This API is
|
// Attempt to pull as many requests out of the queue as possible before awaiting. This API is
|
||||||
|
|
|
@ -59,7 +59,6 @@ const {
|
||||||
ReflectHas,
|
ReflectHas,
|
||||||
ReflectOwnKeys,
|
ReflectOwnKeys,
|
||||||
RegExpPrototypeTest,
|
RegExpPrototypeTest,
|
||||||
RegExpPrototypeExec,
|
|
||||||
SafeRegExp,
|
SafeRegExp,
|
||||||
SafeSet,
|
SafeSet,
|
||||||
SetPrototypeEntries,
|
SetPrototypeEntries,
|
||||||
|
@ -403,11 +402,19 @@ converters.DOMString = function (V, prefix, context, opts = {}) {
|
||||||
return String(V);
|
return String(V);
|
||||||
};
|
};
|
||||||
|
|
||||||
// deno-lint-ignore no-control-regex
|
function isByteString(input) {
|
||||||
const IS_BYTE_STRING = new SafeRegExp(/^[\x00-\xFF]*$/);
|
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) => {
|
converters.ByteString = (V, prefix, context, opts) => {
|
||||||
const x = converters.DOMString(V, prefix, context, opts);
|
const x = converters.DOMString(V, prefix, context, opts);
|
||||||
if (RegExpPrototypeExec(IS_BYTE_STRING, x) === null) {
|
if (!isByteString(x)) {
|
||||||
throw makeException(
|
throw makeException(
|
||||||
TypeError,
|
TypeError,
|
||||||
"is not a valid ByteString",
|
"is not a valid ByteString",
|
||||||
|
|
Loading…
Reference in a new issue