Skip to content

Commit 12c314b

Browse files
perf(http): fix early loop exit; (#7202)
1 parent f6d79e7 commit 12c314b

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lib/adapters/http.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ class Http2Sessions {
6565
sessionTimeout: 1000
6666
}, options);
6767

68-
let authoritySessions;
68+
let authoritySessions = this.sessions[authority];
6969

70-
if ((authoritySessions = this.sessions[authority])) {
70+
if (authoritySessions) {
7171
let len = authoritySessions.length;
7272

7373
for (let i = 0; i < len; i++) {
@@ -93,11 +93,12 @@ class Http2Sessions {
9393

9494
while (i--) {
9595
if (entries[i][0] === session) {
96-
entries.splice(i, 1);
9796
if (len === 1) {
9897
delete this.sessions[authority];
99-
return;
98+
} else {
99+
entries.splice(i, 1);
100100
}
101+
return;
101102
}
102103
}
103104
};
@@ -136,12 +137,12 @@ class Http2Sessions {
136137

137138
session.once('close', removeSession);
138139

139-
let entries = this.sessions[authority], entry = [
140-
session,
141-
options
142-
];
140+
let entry = [
141+
session,
142+
options
143+
];
143144

144-
entries ? this.sessions[authority].push(entry) : authoritySessions = this.sessions[authority] = [entry];
145+
authoritySessions ? authoritySessions.push(entry) : authoritySessions = this.sessions[authority] = [entry];
145146

146147
return session;
147148
}

0 commit comments

Comments
 (0)