Skip to content

Commit

Permalink
perf(cache): avoid Request and Response initialization (nodejs#2610)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsctx authored and crysmags committed Feb 27, 2024
1 parent 0104c2f commit 885bf18
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/cache/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { kHeadersList } = require('../core/symbols')
const { webidl } = require('../fetch/webidl')
const { Response, cloneResponse } = require('../fetch/response')
const { Request } = require('../fetch/request')
const { Headers } = require('../fetch/headers')
const { kState, kHeaders, kGuard, kRealm } = require('../fetch/symbols')
const { fetching } = require('../fetch/index')
const { urlIsHttpHttpsScheme, createDeferredPromise, readAllBytes } = require('../fetch/util')
Expand Down Expand Up @@ -502,8 +503,9 @@ class Cache {

// 5.4.2
for (const request of requests) {
const requestObject = new Request('https://a')
const requestObject = new Request(kConstruct)
requestObject[kState] = request
requestObject[kHeaders] = new Headers(kConstruct)
requestObject[kHeaders][kHeadersList] = request.headersList
requestObject[kHeaders][kGuard] = 'immutable'
requestObject[kRealm] = request.client
Expand Down Expand Up @@ -782,8 +784,9 @@ class Cache {
// 5.5.2
for (const response of responses) {
// 5.5.2.1
const responseObject = new Response(null)
const responseObject = new Response(kConstruct)
responseObject[kState] = response
responseObject[kHeaders] = new Headers(kConstruct)
responseObject[kHeaders][kHeadersList] = response.headersList
responseObject[kHeaders][kGuard] = 'immutable'

Expand Down

0 comments on commit 885bf18

Please sign in to comment.