Skip to content

Commit 4f85f52

Browse files
lrecknagelBethGriggs
authored andcommitted
http: improve performance caused by primordials
Refs: #29766 This works on destructuring primordials whithin libs/_http_agent PR-URL: #30416 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
1 parent b7bd84f commit 4f85f52

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

‎lib/_http_agent.js‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@
2121

2222
'use strict';
2323

24-
const{ Object }=primordials;
24+
const{
25+
Object: {
26+
setPrototypeOf: ObjectSetPrototypeOf,
27+
keys: ObjectKeys,
28+
values: ObjectValues
29+
}
30+
}=primordials;
2531

2632
constnet=require('net');
2733
constEventEmitter=require('events');
@@ -124,8 +130,8 @@ function Agent(options) {
124130
// Don't emit keylog events unless there is a listener for them.
125131
this.on('newListener',maybeEnableKeylog);
126132
}
127-
Object.setPrototypeOf(Agent.prototype,EventEmitter.prototype);
128-
Object.setPrototypeOf(Agent,EventEmitter);
133+
ObjectSetPrototypeOf(Agent.prototype,EventEmitter.prototype);
134+
ObjectSetPrototypeOf(Agent,EventEmitter);
129135

130136
functionmaybeEnableKeylog(eventName){
131137
if(eventName==='keylog'){
@@ -136,7 +142,7 @@ function maybeEnableKeylog(eventName) {
136142
agent.emit('keylog',keylog,this);
137143
};
138144
// Existing sockets will start listening on keylog now.
139-
constsockets=Object.values(this.sockets);
145+
constsockets=ObjectValues(this.sockets);
140146
for(leti=0;i<sockets.length;i++){
141147
sockets[i].on('keylog',this[kOnKeylog]);
142148
}
@@ -371,7 +377,7 @@ Agent.prototype.destroy = function destroy() {
371377
constsets=[this.freeSockets,this.sockets];
372378
for(lets=0;s<sets.length;s++){
373379
constset=sets[s];
374-
constkeys=Object.keys(set);
380+
constkeys=ObjectKeys(set);
375381
for(letv=0;v<keys.length;v++){
376382
constsetName=set[keys[v]];
377383
for(letn=0;n<setName.length;n++){

0 commit comments

Comments
 (0)