Skip to content

Commit 11a334b

Browse files
committed
Improve performance of removing connections from pools
Use the built in splice method to avoid reordering the queue
1 parent 7c55a07 commit 11a334b

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

lib/pool.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,10 @@ Pool.prototype.escapeId = function escapeId(value) {
217217

218218
function spliceConnection(queue, connection) {
219219
var len = queue.length;
220-
if (len) {
221-
if (queue.get(len - 1) === connection) {
222-
queue.pop();
223-
} else {
224-
for (; --len; ) {
225-
if (queue.get(0) === connection) {
226-
queue.shift();
227-
break;
228-
}
229-
queue.push(queue.shift());
230-
}
220+
for (var i = 0; i < len; i++) {
221+
if (queue.get(i) === connection) {
222+
queue.removeOne(i);
223+
break;
231224
}
232225
}
233226
}

0 commit comments

Comments
 (0)