Skip to content

Commit

Permalink
Pluck out the old wait instead of using splice.
Browse files Browse the repository at this point in the history
 % node benchmark/increment/notify.js
 signal notify 1 x 5,274,081 ops/sec ±2.40% (92 runs sampled)
_signal notify 1 x 4,251,434 ops/sec ±3.44% (94 runs sampled)
 signal notify 2 x 5,296,992 ops/sec ±3.53% (88 runs sampled)
_signal notify 2 x 4,247,333 ops/sec ±0.80% (93 runs sampled)
 signal notify 3 x 5,393,405 ops/sec ±2.60% (90 runs sampled)
_signal notify 3 x 4,259,548 ops/sec ±0.83% (93 runs sampled)
 signal notify 4 x 5,447,035 ops/sec ±0.61% (95 runs sampled)
_signal notify 4 x 4,173,330 ops/sec ±2.69% (93 runs sampled)
Fastest is  signal notify 4, signal notify 2
  • Loading branch information
flatheadmill committed Nov 25, 2018
1 parent 6730133 commit 4805790
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion _signal.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Signal.prototype.notify = function () {
// cancel it. We're going to want to be able cancel both exiting waits
// and waits added during the notification.
var waits = this._waits
this._cancels.unshift(this._waits = [])
this._cancels.push(this._waits = [])

// We shift first so we don't wreck the array if a wait cancels itself.
while (waits.length != 0) {
Expand Down
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

0 comments on commit 4805790

Please sign in to comment.