Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace expensive arr.splice() with unordered-array-remove in hot code #707

Merged
merged 1 commit into from Mar 29, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Replace expensive arr.splice() with unordered-array-remove in hot code

  • Loading branch information
feross committed Mar 29, 2016
commit 1973007f7fa336774d20d7a0578894832c25d00b
@@ -1,3 +1,4 @@
var arrayRemove = require('unordered-array-remove')
var debug = require('debug')('webtorrent:peer')
var Wire = require('bittorrent-protocol')

@@ -240,8 +241,7 @@ Peer.prototype.destroy = function (err) {
self.wire = null

if (swarm && wire) {
var index = swarm.wires.indexOf(wire)
if (index >= 0) swarm.wires.splice(index, 1)
arrayRemove(swarm.wires, swarm.wires.indexOf(wire))
}
if (conn) {
conn.on('error', noop)
@@ -1,5 +1,6 @@
module.exports = Server

var arrayRemove = require('unordered-array-remove')
var debug = require('debug')('webtorrent:server')
var http = require('http')
var mime = require('mime')
@@ -17,8 +18,7 @@ function Server (torrent, opts) {
socket.setTimeout(36000000)
sockets.push(socket)
socket.on('close', function () {
var index = sockets.indexOf(socket)
if (index >= 0) sockets.splice(index, 1)
arrayRemove(sockets, sockets.indexOf(socket))
})
})

@@ -1,5 +1,6 @@
module.exports = TCPPool

var arrayRemove = require('unordered-array-remove')
var debug = require('debug')('webtorrent:tcp-pool')
var net = require('net') // browser exclude

@@ -198,7 +199,7 @@ TCPPool.prototype._onConnection = function (conn) {
conn.once('close', removePendingConn)

function removePendingConn () {
self.pendingConns.splice(self.pendingConns.indexOf(conn))
arrayRemove(self.pendingConns, self.pendingConns.indexOf(conn))
}

var peer = Peer.createTCPIncomingPeer(conn)
@@ -64,6 +64,7 @@
"torrent-discovery": "^7.0.0",
"torrent-piece": "^1.0.0",
"uniq": "^1.0.1",
"unordered-array-remove": "feross/unordered-array-remove",
"ut_metadata": "^3.0.2",
"ut_pex": "^1.0.1",
"xtend": "^4.0.0",
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.