Skip to content

Commit a663d4d

Browse files
milendfacebook-github-bot-7
authored andcommitted
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
1 parent ca016e4 commit a663d4d

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Libraries/JavaScriptAppEngine/System/JSTimers/JSTimersExecution.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,11 @@ var JSTimersExecution = {
121121
var passImmediates = JSTimersExecution.immediates.slice();
122122
JSTimersExecution.immediates = [];
123123

124-
passImmediates.forEach((timerID) => {
125-
JSTimersExecution.callTimer(timerID);
126-
});
124+
// Use for loop rather than forEach as per @vjeux's advice
125+
// https://github.com/facebook/react-native/commit/c8fd9f7588ad02d2293cac7224715f4af7b0f352#commitcomment-14570051
126+
for (var i = 0; i < passImmediates.length; ++i) {
127+
JSTimersExecution.callTimer(passImmediates[i]);
128+
}
127129
}
128130

129131
BridgeProfiling.profileEnd();

0 commit comments

Comments
 (0)