From 2903410aa8393a73dfbc75c5a9ba31c21ccb70dc Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 26 Mar 2015 23:56:26 +0100 Subject: [PATCH] src: don't lazy-load timer globals Don't lazy-load setInterval(), setTimeout(), etc. Most applications are going to need them and routing every call through NativeModule.require() and Function#apply() is not exactly efficient. PR-URL: https://github.com/iojs/io.js/pull/1280 Reviewed-By: Jeremiah Senkpiel --- src/node.js | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/src/node.js b/src/node.js index 8ad727b7822ebf..63465290a0c351 100644 --- a/src/node.js +++ b/src/node.js @@ -173,35 +173,13 @@ }; startup.globalTimeouts = function() { - global.setTimeout = function() { - var t = NativeModule.require('timers'); - return t.setTimeout.apply(this, arguments); - }; - - global.setInterval = function() { - var t = NativeModule.require('timers'); - return t.setInterval.apply(this, arguments); - }; - - global.clearTimeout = function() { - var t = NativeModule.require('timers'); - return t.clearTimeout.apply(this, arguments); - }; - - global.clearInterval = function() { - var t = NativeModule.require('timers'); - return t.clearInterval.apply(this, arguments); - }; - - global.setImmediate = function() { - var t = NativeModule.require('timers'); - return t.setImmediate.apply(this, arguments); - }; - - global.clearImmediate = function() { - var t = NativeModule.require('timers'); - return t.clearImmediate.apply(this, arguments); - }; + const timers = NativeModule.require('timers'); + global.clearImmediate = timers.clearImmediate; + global.clearInterval = timers.clearInterval; + global.clearTimeout = timers.clearTimeout; + global.setImmediate = timers.setImmediate; + global.setInterval = timers.setInterval; + global.setTimeout = timers.setTimeout; }; startup.globalConsole = function() {