Merge pull request #202 from feross/unordered-array-remove

Use unordered-array-remove for better performance!
This commit is contained in:
Feross Aboukhadijeh 2017-02-13 17:38:03 -08:00 committed by GitHub
commit 5375506f56
4 changed files with 7 additions and 3 deletions

View File

@ -1,5 +1,6 @@
module.exports = HTTPTracker
var arrayRemove = require('unordered-array-remove')
var bencode = require('bencode')
var compact2string = require('compact2string')
var debug = require('debug')('bittorrent-tracker:http-tracker')
@ -133,7 +134,7 @@ HTTPTracker.prototype._request = function (requestUrl, params, cb) {
function cleanup () {
if (request) {
self.cleanupFns.splice(self.cleanupFns.indexOf(cleanup), 1)
arrayRemove(self.cleanupFns, self.cleanupFns.indexOf(cleanup))
request.abort()
request = null
}

View File

@ -1,5 +1,6 @@
module.exports = UDPTracker
var arrayRemove = require('unordered-array-remove')
var BN = require('bn.js')
var Buffer = require('safe-buffer').Buffer
var compact2string = require('compact2string')
@ -110,7 +111,7 @@ UDPTracker.prototype._request = function (opts) {
timeout = null
}
if (socket) {
self.cleanupFns.splice(self.cleanupFns.indexOf(cleanup), 1)
arrayRemove(self.cleanupFns, self.cleanupFns.indexOf(cleanup))
socket.removeListener('error', onError)
socket.removeListener('message', onSocketMessage)
socket.on('error', noop) // ignore all future errors

View File

@ -1,5 +1,6 @@
module.exports = Swarm
var arrayRemove = require('unordered-array-remove')
var debug = require('debug')('bittorrent-tracker:swarm')
var LRU = require('lru')
var randomIterate = require('random-iterate')
@ -103,7 +104,7 @@ Swarm.prototype._onAnnounceStopped = function (params, peer, id) {
// swarms that this peer is participating in.
if (peer.socket) {
var index = peer.socket.infoHashes.indexOf(this.infoHash)
peer.socket.infoHashes.splice(index, 1)
arrayRemove(peer.socket.infoHashes, index)
}
this.peers.remove(id)

View File

@ -40,6 +40,7 @@
"simple-websocket": "^4.0.0",
"string2compact": "^1.1.1",
"uniq": "^1.0.1",
"unordered-array-remove": "^1.0.2",
"ws": "^1.0.0",
"xtend": "^4.0.0"
},