-
Notifications
You must be signed in to change notification settings - Fork 570
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fetch: improve performance of isValidHeaderValue (#3098)
- Loading branch information
Showing
3 changed files
with
84 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { bench, run } from 'mitata' | ||
import { isValidHeaderValue } from '../../lib/web/fetch/util.js' | ||
|
||
const valid = 'valid123' | ||
const invalidNUL = 'invalid\x00' | ||
const invalidCR = 'invalid\r' | ||
const invalidLF = 'invalid\n' | ||
const invalidTrailingTab = 'invalid\t' | ||
const invalidLeadingTab = '\tinvalid' | ||
const invalidTrailingSpace = 'invalid ' | ||
const invalidLeadingSpace = ' invalid' | ||
|
||
bench('isValidHeaderValue valid', () => { | ||
isValidHeaderValue(valid) | ||
}) | ||
bench('isValidHeaderValue invalid containing NUL', () => { | ||
isValidHeaderValue(invalidNUL) | ||
}) | ||
bench('isValidHeaderValue invalid containing CR', () => { | ||
isValidHeaderValue(invalidCR) | ||
}) | ||
bench('isValidHeaderValue invalid containing LF', () => { | ||
isValidHeaderValue(invalidLF) | ||
}) | ||
bench('isValidHeaderValue invalid trailing TAB', () => { | ||
isValidHeaderValue(invalidTrailingTab) | ||
}) | ||
bench('isValidHeaderValue invalid leading TAB', () => { | ||
isValidHeaderValue(invalidLeadingTab) | ||
}) | ||
bench('isValidHeaderValue invalid trailing SPACE', () => { | ||
isValidHeaderValue(invalidTrailingSpace) | ||
}) | ||
bench('isValidHeaderValue invalid leading SPACE', () => { | ||
isValidHeaderValue(invalidLeadingSpace) | ||
}) | ||
|
||
await run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters