Created
December 10, 2012 16:03
-
-
Save mteece/4251481 to your computer and use it in GitHub Desktop.
Cache the array length to speed up for loop. Preassign the array length instead of testing it again in every step.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* //Below code is causing the slowdown | |
| for (var i = 0; i < records.length; i++) { | |
| var record = new recordTemplate(records[i]); | |
| this.store.add(record); | |
| } | |
| }, | |
| */ | |
| // Better code | |
| var records2 = []; | |
| var recLength = records.length; | |
| for (var i = 0; i < recLength; i++) { | |
| records2.push(new recordTemplate(records[i])); | |
| } | |
| this.store.insert(0, records2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment