Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: improve cookie parsing performance #1931

Merged
merged 1 commit into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/cookies/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const { maxNameValuePairSize, maxAttributeValueSize } = require('./constants')
const { isCTLExcludingHtab } = require('./util')
const { collectASequenceOfCodePoints } = require('../fetch/dataURL')
const { collectASequenceOfCodePointsFast } = require('../fetch/dataURL')
const assert = require('assert')

/**
Expand Down Expand Up @@ -32,7 +32,7 @@ function parseSetCookie (header) {
// (including the %x3B (";") in question).
const position = { position: 0 }

nameValuePair = collectASequenceOfCodePoints((char) => char !== ';', header, position)
nameValuePair = collectASequenceOfCodePointsFast(';', header, position)
unparsedAttributes = header.slice(position.position)
} else {
// Otherwise:
Expand All @@ -54,8 +54,8 @@ function parseSetCookie (header) {
// empty) value string consists of the characters after the first
// %x3D ("=") character.
const position = { position: 0 }
name = collectASequenceOfCodePoints(
(char) => char !== '=',
name = collectASequenceOfCodePointsFast(
'=',
nameValuePair,
position
)
Expand Down Expand Up @@ -106,8 +106,8 @@ function parseUnparsedAttributes (unparsedAttributes, cookieAttributeList = {})
if (unparsedAttributes.includes(';')) {
// 1. Consume the characters of the unparsed-attributes up to, but
// not including, the first %x3B (";") character.
cookieAv = collectASequenceOfCodePoints(
(char) => char !== ';',
cookieAv = collectASequenceOfCodePointsFast(
';',
unparsedAttributes,
{ position: 0 }
)
Expand All @@ -134,8 +134,8 @@ function parseUnparsedAttributes (unparsedAttributes, cookieAttributeList = {})
// character.
const position = { position: 0 }

attributeName = collectASequenceOfCodePoints(
(char) => char !== '=',
attributeName = collectASequenceOfCodePointsFast(
'=',
cookieAv,
position
)
Expand Down
1 change: 1 addition & 0 deletions lib/fetch/dataURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ module.exports = {
dataURLProcessor,
URLSerializer,
collectASequenceOfCodePoints,
collectASequenceOfCodePointsFast,
stringPercentDecode,
parseMIMEType,
collectAnHTTPQuotedString,
Expand Down