summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Sedoi <bsnote@gmail.com>2015-11-26 15:55:05 +0000
committerJeremiah Senkpiel <fishrock123@rocketmail.com>2015-12-02 11:14:28 -0500
commitfbcd687c08363053e2aff6ad29d906cc8df97f79 (patch)
tree355a73a71e71a37a64337c43cb513b1caaedb4ca
parent8eb153d00bf5b486854a16e72d1b6f3f10418402 (diff)
downloadandroid-node-v8-fbcd687c08363053e2aff6ad29d906cc8df97f79.tar.gz
android-node-v8-fbcd687c08363053e2aff6ad29d906cc8df97f79.tar.bz2
android-node-v8-fbcd687c08363053e2aff6ad29d906cc8df97f79.zip
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 <rtrott@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
-rw-r--r--lib/timers.js18
1 files changed, 9 insertions, 9 deletions
diff --git a/lib/timers.js b/lib/timers.js
index 0b1ce934d4..24dc7e1c26 100644
--- a/lib/timers.js
+++ b/lib/timers.js
@@ -193,21 +193,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;
@@ -248,20 +248,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;
@@ -273,7 +273,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)