Skip to content

Commit

Permalink
perf: improve cookie parsing performance (nodejs#1931)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev authored and anonrig committed Apr 4, 2023
1 parent 1c3c204 commit 82d9c6c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
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

0 comments on commit 82d9c6c

Please sign in to comment.