Skip to content

Commit

Permalink
Use push.apply in unlatch.
Browse files Browse the repository at this point in the history
 % node benchmark/increment/unlatch.js
 signal unlatch 1 x 17,301,870 ops/sec ±0.88% (91 runs sampled)
_signal unlatch 1 x 7,994,106 ops/sec ±2.06% (92 runs sampled)
 signal unlatch 2 x 17,037,813 ops/sec ±2.63% (85 runs sampled)
_signal unlatch 2 x 8,373,249 ops/sec ±0.29% (91 runs sampled)
 signal unlatch 3 x 17,566,441 ops/sec ±2.50% (92 runs sampled)
_signal unlatch 3 x 8,339,125 ops/sec ±0.46% (95 runs sampled)
 signal unlatch 4 x 17,570,954 ops/sec ±2.02% (93 runs sampled)
_signal unlatch 4 x 8,342,331 ops/sec ±0.43% (97 runs sampled)
Fastest is  signal unlatch 4, signal unlatch 3
  • Loading branch information
flatheadmill committed Nov 25, 2018
1 parent 4805790 commit 96ccbf8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 12 additions & 1 deletion _signal.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,18 @@ Signal.prototype.notify = function () {
waited.callback.apply(null, arguments)
}

this._cancels.splice(this._cancels.indexOf(waits), 1)
var i = 0
while (i < this._cancels.length) {
if (this._cancels[i] === waits) {
break
}
i++
}
while (i <= this._cancels.length - 1) {
this._cancels[i] = this._cancels[i + 1]
i++
}
this._cancels.length--
}
}

Expand Down
4 changes: 3 additions & 1 deletion signal.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ Signal.prototype.notify = function () {
//
Signal.prototype.unlatch = function () {
if (this.open == null) {
this.notify.apply(this, this.open = Array.prototype.slice.call(arguments))
this.open = []
this.open.push.apply(this.open, arguments)
this.notify.apply(this, this.open)
}
}

Expand Down

0 comments on commit 96ccbf8

Please sign in to comment.