From a663d4d8d5daa601c43d85871fe8b335eb848dd2 Mon Sep 17 00:00:00 2001 From: Milen Dzhumerov Date: Wed, 25 Nov 2015 07:22:28 -0800 Subject: [PATCH] Use for-loop instead of forEach() in a hot path Summary: public Replaces the usage of forEach() with a for loop on a hot code path Reviewed By: tadeuzagallo Differential Revision: D2690727 fb-gh-sync-id: b7cbcda5cf80a0e31753f49c01e145abb789f3e5 --- .../System/JSTimers/JSTimersExecution.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Libraries/JavaScriptAppEngine/System/JSTimers/JSTimersExecution.js b/Libraries/JavaScriptAppEngine/System/JSTimers/JSTimersExecution.js index bc2b74d22..07a324d41 100644 --- a/Libraries/JavaScriptAppEngine/System/JSTimers/JSTimersExecution.js +++ b/Libraries/JavaScriptAppEngine/System/JSTimers/JSTimersExecution.js @@ -121,9 +121,11 @@ var JSTimersExecution = { var passImmediates = JSTimersExecution.immediates.slice(); JSTimersExecution.immediates = []; - passImmediates.forEach((timerID) => { - JSTimersExecution.callTimer(timerID); - }); + // Use for loop rather than forEach as per @vjeux's advice + // https://github.com/facebook/react-native/commit/c8fd9f7588ad02d2293cac7224715f4af7b0f352#commitcomment-14570051 + for (var i = 0; i < passImmediates.length; ++i) { + JSTimersExecution.callTimer(passImmediates[i]); + } } BridgeProfiling.profileEnd();