From: Andrei Sedoi Date: Thu, 26 Nov 2015 15:55:05 +0000 (+0000) Subject: timers: optimize callback call: bind -> arrow X-Git-Tag: v4.2.5~151 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=86b47e8dc012b38460e6950a63786c5198552afb;p=platform%2Fupstream%2Fnodejs.git timers: optimize callback call: bind -> arrow ES6 arrow functions are much more efficient than `.bind()` functions. PR-URL: https://github.com/nodejs/node/pull/4038 Reviewed-By: Rich Trott Reviewed-By: Jeremiah Senkpiel --- diff --git a/lib/timers.js b/lib/timers.js index e4b27fd..8cfd1cb 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -192,21 +192,21 @@ exports.setTimeout = function(callback, after) { case 2: break; case 3: - ontimeout = callback.bind(timer, arguments[2]); + ontimeout = () => callback.call(timer, arguments[2]); break; case 4: - ontimeout = callback.bind(timer, arguments[2], arguments[3]); + ontimeout = () => callback.call(timer, arguments[2], arguments[3]); break; case 5: ontimeout = - callback.bind(timer, arguments[2], arguments[3], arguments[4]); + () => callback.call(timer, arguments[2], arguments[3], arguments[4]); break; // slow case default: var args = new Array(length - 2); for (var i = 2; i < length; i++) args[i - 2] = arguments[i]; - ontimeout = callback.apply.bind(callback, timer, args); + ontimeout = () => callback.apply(timer, args); break; } timer._onTimeout = ontimeout; @@ -247,20 +247,20 @@ exports.setInterval = function(callback, repeat) { case 2: break; case 3: - ontimeout = callback.bind(timer, arguments[2]); + ontimeout = () => callback.call(timer, arguments[2]); break; case 4: - ontimeout = callback.bind(timer, arguments[2], arguments[3]); + ontimeout = () => callback.call(timer, arguments[2], arguments[3]); break; case 5: ontimeout = - callback.bind(timer, arguments[2], arguments[3], arguments[4]); + () => callback.call(timer, arguments[2], arguments[3], arguments[4]); break; default: var args = new Array(length - 2); for (var i = 2; i < length; i += 1) args[i - 2] = arguments[i]; - ontimeout = callback.apply.bind(callback, timer, args); + ontimeout = () => callback.apply(timer, args); break; } timer._onTimeout = wrapper; @@ -272,7 +272,7 @@ exports.setInterval = function(callback, repeat) { return timer; function wrapper() { - timer._repeat.call(this); + timer._repeat(); // Timer might be closed - no point in restarting it if (!timer._repeat)