Created
January 14, 2016 04:53
-
-
Save rvagg/e0079429a5ebbd7d8f27 to your computer and use it in GitHub Desktop.
timer deopt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 8550e47a3da1537d1eb5abc590615ed09ac2b9b2 | |
Author: Rod Vagg <rod@vagg.org> | |
Date: Thu Jan 14 15:25:35 2016 +1100 | |
_timer | |
diff --git a/lib/timers.js b/lib/timers.js | |
index 27c03ad..2c95154 100644 | |
--- a/lib/timers.js | |
+++ b/lib/timers.js | |
@@ -90,16 +90,18 @@ function insert(item, unrefed) { | |
// Make a new linked list of timers. | |
// The list object is a TimerWrap, a C++ handle backing the timers for | |
// efficiency, and the linked list is appended onto it. | |
- list = new Timer(); | |
- if (unrefed === true) list.unref(); | |
+ list = {} | |
+ list._timer = new Timer(); | |
+ list._timer._list = list; | |
+ if (unrefed === true) list._timer.unref(); | |
list._unrefed = unrefed; | |
- list.start(msecs, 0); | |
+ list._timer.start(msecs, 0); | |
L.init(list); | |
lists[msecs] = list; | |
list.msecs = msecs; | |
- list[kOnTimeout] = listOnTimeout; | |
+ list._timer[kOnTimeout] = listOnTimeout; | |
} | |
L.append(list, item); | |
@@ -108,7 +110,7 @@ function insert(item, unrefed) { | |
function listOnTimeout() { | |
var msecs = this.msecs; | |
- var list = this; | |
+ var list = this._list; | |
debug('timeout callback %d', msecs); | |
@@ -124,7 +126,7 @@ function listOnTimeout() { | |
// - There are more timers scheduled for later in the list. (Most common) | |
// - The earliest timer was canceled (unenrolled). (Less common) | |
if (diff < msecs) { | |
- list.start(msecs - diff, 0); | |
+ list._timer.start(msecs - diff, 0); | |
debug('%d list wait because diff is %d', msecs, diff); | |
return; | |
} | |
@@ -161,7 +163,7 @@ function listOnTimeout() { | |
// As such, we can remove and clean up the timer list. (The TimerWrap) | |
debug('%d list empty', msecs); | |
assert(L.isEmpty(list)); | |
- list.close(); | |
+ list._timer.close(); | |
if (list._unrefed === true) { | |
delete unrefedLists[msecs]; | |
} else { | |
@@ -194,7 +196,7 @@ function _tryOnTimeout(timer, list) { | |
function listOnTimeoutNT(list) { | |
- list[kOnTimeout](); | |
+ list._timer[kOnTimeout](); | |
} | |
@@ -211,7 +213,7 @@ function reuse(item) { | |
// if empty - reuse the watcher | |
if (list && L.isEmpty(list)) { | |
debug('reuse hit'); | |
- list.stop(); | |
+ list._timer.stop(); | |
delete refedLists[item._idleTimeout]; | |
return list; | |
} | |
@@ -225,7 +227,7 @@ const unenroll = exports.unenroll = function(item) { | |
var list = reuse(item); | |
if (list) { | |
debug('unenroll: list empty'); | |
- list.close(); | |
+ list._timer.close(); | |
} | |
// if active is called later, then we want to make sure not to insert again | |
item._idleTimeout = -1; | |
@@ -428,6 +430,8 @@ Timeout.prototype.unref = function() { | |
} | |
var handle = reuse(this); | |
+ if (handle) | |
+ handle = handle._timer; | |
this._handle = handle || new Timer(); | |
this._handle.owner = this; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment