mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2024-12-14 19:36:24 +00:00
Merge pull request #202 from feross/unordered-array-remove
Use unordered-array-remove for better performance!
This commit is contained in:
commit
5375506f56
@ -1,5 +1,6 @@
|
|||||||
module.exports = HTTPTracker
|
module.exports = HTTPTracker
|
||||||
|
|
||||||
|
var arrayRemove = require('unordered-array-remove')
|
||||||
var bencode = require('bencode')
|
var bencode = require('bencode')
|
||||||
var compact2string = require('compact2string')
|
var compact2string = require('compact2string')
|
||||||
var debug = require('debug')('bittorrent-tracker:http-tracker')
|
var debug = require('debug')('bittorrent-tracker:http-tracker')
|
||||||
@ -133,7 +134,7 @@ HTTPTracker.prototype._request = function (requestUrl, params, cb) {
|
|||||||
|
|
||||||
function cleanup () {
|
function cleanup () {
|
||||||
if (request) {
|
if (request) {
|
||||||
self.cleanupFns.splice(self.cleanupFns.indexOf(cleanup), 1)
|
arrayRemove(self.cleanupFns, self.cleanupFns.indexOf(cleanup))
|
||||||
request.abort()
|
request.abort()
|
||||||
request = null
|
request = null
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
module.exports = UDPTracker
|
module.exports = UDPTracker
|
||||||
|
|
||||||
|
var arrayRemove = require('unordered-array-remove')
|
||||||
var BN = require('bn.js')
|
var BN = require('bn.js')
|
||||||
var Buffer = require('safe-buffer').Buffer
|
var Buffer = require('safe-buffer').Buffer
|
||||||
var compact2string = require('compact2string')
|
var compact2string = require('compact2string')
|
||||||
@ -110,7 +111,7 @@ UDPTracker.prototype._request = function (opts) {
|
|||||||
timeout = null
|
timeout = null
|
||||||
}
|
}
|
||||||
if (socket) {
|
if (socket) {
|
||||||
self.cleanupFns.splice(self.cleanupFns.indexOf(cleanup), 1)
|
arrayRemove(self.cleanupFns, self.cleanupFns.indexOf(cleanup))
|
||||||
socket.removeListener('error', onError)
|
socket.removeListener('error', onError)
|
||||||
socket.removeListener('message', onSocketMessage)
|
socket.removeListener('message', onSocketMessage)
|
||||||
socket.on('error', noop) // ignore all future errors
|
socket.on('error', noop) // ignore all future errors
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
module.exports = Swarm
|
module.exports = Swarm
|
||||||
|
|
||||||
|
var arrayRemove = require('unordered-array-remove')
|
||||||
var debug = require('debug')('bittorrent-tracker:swarm')
|
var debug = require('debug')('bittorrent-tracker:swarm')
|
||||||
var LRU = require('lru')
|
var LRU = require('lru')
|
||||||
var randomIterate = require('random-iterate')
|
var randomIterate = require('random-iterate')
|
||||||
@ -103,7 +104,7 @@ Swarm.prototype._onAnnounceStopped = function (params, peer, id) {
|
|||||||
// swarms that this peer is participating in.
|
// swarms that this peer is participating in.
|
||||||
if (peer.socket) {
|
if (peer.socket) {
|
||||||
var index = peer.socket.infoHashes.indexOf(this.infoHash)
|
var index = peer.socket.infoHashes.indexOf(this.infoHash)
|
||||||
peer.socket.infoHashes.splice(index, 1)
|
arrayRemove(peer.socket.infoHashes, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.peers.remove(id)
|
this.peers.remove(id)
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
"simple-websocket": "^4.0.0",
|
"simple-websocket": "^4.0.0",
|
||||||
"string2compact": "^1.1.1",
|
"string2compact": "^1.1.1",
|
||||||
"uniq": "^1.0.1",
|
"uniq": "^1.0.1",
|
||||||
|
"unordered-array-remove": "^1.0.2",
|
||||||
"ws": "^1.0.0",
|
"ws": "^1.0.0",
|
||||||
"xtend": "^4.0.0"
|
"xtend": "^4.0.0"
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user