Permalink
Browse files

setTimeout speedup: do not calculate Timeout._when property

  • Loading branch information...
wicked
wicked committed Oct 25, 2012
1 parent 78dbb15 commit 63b38760c25f15b65421766fca635543382d1556
Showing with 3 additions and 2 deletions.
  1. +3 −2 lib/timers.js
View
@@ -248,12 +248,13 @@ var Timeout = function(after) {
this._idleTimeout = after;
this._idlePrev = this;
this._idleNext = this;
- this._when = Date.now() + after;
+ this._idleStart = null;
};
Timeout.prototype.unref = function() {
if (!this._handle) {
- var delay = this._when - Date.now();
+ if (!this._idleStart) this._idleStart = Date.now();
+ var delay = this._idleStart + this._idleTimeout - Date.now();
if (delay < 0) delay = 0;
exports.unenroll(this);
this._handle = new Timer();

0 comments on commit 63b3876

Please sign in to comment.