Skip to content

Commit 40eb738

Browse files
committed
Use indexOf to find connection when removing from pool
fixes #611
1 parent c400c86 commit 40eb738

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

Changes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ you spot any mistakes.
66

77
## HEAD
88

9+
* Use indexOf instead of for loops removing conn from pool #611
10+
911
## v2.1.1 (2014-03-13)
1012

1113
* fix authentication w/password failure for node.js 0.10.5 #746 #752

lib/Pool.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,16 @@ Pool.prototype.query = function (sql, values, cb) {
148148
};
149149

150150
Pool.prototype._removeConnection = function(connection) {
151-
var i;
151+
var index;
152152

153-
for (i = 0; i < this._allConnections.length; i++) {
154-
if (this._allConnections[i] === connection) {
155-
this._allConnections.splice(i, 1);
156-
break;
157-
}
153+
if ((index = this._allConnections.indexOf(connection)) !== -1) {
154+
// Remove connection from all connections
155+
this._allConnections.splice(index, 1);
158156
}
159157

160-
for (i = 0; i < this._freeConnections.length; i++) {
161-
if (this._freeConnections[i] === connection) {
162-
this._freeConnections.splice(i, 1);
163-
break;
164-
}
158+
if ((index = this._freeConnections.indexOf(connection)) !== -1) {
159+
// Remove connection from free connections
160+
this._freeConnections.splice(index, 1);
165161
}
166162

167163
this.releaseConnection(connection);

0 commit comments

Comments
 (0)