Skip to content
This repository has been archived by the owner on Aug 31, 2018. It is now read-only.

Commit

Permalink
timers: cleanup extraneous property on Immediates
Browse files Browse the repository at this point in the history
This was originally changed in 6f75b66
but it appears unnecessary and benhcmark results show little difference
without the extra property.

Refs: nodejs/node#6436
PR-URL: nodejs/node#16355
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
  • Loading branch information
Fishrock123 authored and addaleax committed Oct 26, 2017
1 parent cd9fdba commit 458c55a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
25 changes: 11 additions & 14 deletions lib/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,6 @@ function processImmediate() {
if (domain)
domain.enter();

immediate._callback = immediate._onImmediate;

// Save next in case `clearImmediate(immediate)` is called from callback
var next = immediate._idleNext;

Expand Down Expand Up @@ -764,8 +762,8 @@ function tryOnImmediate(immediate, oldTail) {
runCallback(immediate);
threw = false;
} finally {
// clearImmediate checks _callback === null for kDestroy hooks.
immediate._callback = null;
// clearImmediate checks _onImmediate === null for kDestroy hooks.
immediate._onImmediate = null;
if (!threw)
emitAfter(immediate[async_id_symbol]);
if (async_hook_fields[kDestroy] > 0 && !immediate._destroyed) {
Expand Down Expand Up @@ -794,21 +792,21 @@ function tryOnImmediate(immediate, oldTail) {
function runCallback(timer) {
const argv = timer._argv;
const argc = argv ? argv.length : 0;
if (typeof timer._callback !== 'function')
return promiseResolve(timer._callback, argv[0]);
if (typeof timer._onImmediate !== 'function')
return promiseResolve(timer._onImmediate, argv[0]);
switch (argc) {
// fast-path callbacks with 0-3 arguments
case 0:
return timer._callback();
return timer._onImmediate();
case 1:
return timer._callback(argv[0]);
return timer._onImmediate(argv[0]);
case 2:
return timer._callback(argv[0], argv[1]);
return timer._onImmediate(argv[0], argv[1]);
case 3:
return timer._callback(argv[0], argv[1], argv[2]);
return timer._onImmediate(argv[0], argv[1], argv[2]);
// more than 3 arguments run slower with .apply
default:
return Function.prototype.apply.call(timer._callback, timer, argv);
return Function.prototype.apply.call(timer._onImmediate, timer, argv);
}
}

Expand All @@ -818,7 +816,7 @@ function Immediate() {
// so have caller annotate the object (node v6.0.0, v8 5.0.71.35)
this._idleNext = null;
this._idlePrev = null;
this._callback = null;
this._onImmediate = null;
this._argv = null;
this._onImmediate = null;
this._destroyed = false;
Expand Down Expand Up @@ -869,7 +867,6 @@ exports.setImmediate = setImmediate;
function createImmediate(args, callback) {
// declaring it `const immediate` causes v6.0.0 to deoptimize this function
var immediate = new Immediate();
immediate._callback = callback;
immediate._argv = args;
immediate._onImmediate = callback;

Expand All @@ -888,7 +885,7 @@ exports.clearImmediate = function(immediate) {
if (!immediate) return;

if (async_hook_fields[kDestroy] > 0 &&
immediate._callback !== null &&
immediate._onImmediate !== null &&
!immediate._destroyed) {
emitDestroy(immediate[async_id_symbol]);
immediate._destroyed = true;
Expand Down
2 changes: 1 addition & 1 deletion test/message/unhandled_promise_trace_warnings.out
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
at rejectionHandled (internal/process/promises.js:*)
at *
at Promise.catch *
at Immediate.setImmediate [as _onImmediate] (*test*message*unhandled_promise_trace_warnings.js:*)
at Immediate.setImmediate (*test*message*unhandled_promise_trace_warnings.js:*)
at *
at *
at *

0 comments on commit 458c55a

Please sign in to comment.