Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 08eb055

Browse files
committed
perf(ngRepeat): simplify code and remove duplicate array.length access
minimal perf gain (~2ms)
1 parent 2ef2588 commit 08eb055

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/ng/directive/ngRepeat.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,13 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
310310
// Same as lastBlockMap but it has the current state. It will become the
311311
// lastBlockMap on the next iteration.
312312
nextBlockMap = createMap(),
313-
arrayLength,
313+
collectionLength,
314314
key, value, // key/value of iteration
315315
trackById,
316316
trackByIdFn,
317317
collectionKeys,
318318
block, // last object information {scope, element, id}
319-
nextBlockOrder = [],
319+
nextBlockOrder,
320320
elementsToRemove;
321321

322322
if (aliasAs) {
@@ -338,11 +338,11 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
338338
collectionKeys.sort();
339339
}
340340

341-
arrayLength = collectionKeys.length;
341+
collectionLength = collectionKeys.length;
342+
nextBlockOrder = new Array(collectionLength);
342343

343344
// locate existing items
344-
length = nextBlockOrder.length = collectionKeys.length;
345-
for (index = 0; index < length; index++) {
345+
for (index = 0; index < collectionLength; index++) {
346346
key = (collection === collectionKeys) ? index : collectionKeys[index];
347347
value = collection[key];
348348
trackById = trackByIdFn(key, value, index);
@@ -382,7 +382,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
382382
}
383383

384384
// we are not using forEach for perf reasons (trying to avoid #call)
385-
for (index = 0, length = collectionKeys.length; index < length; index++) {
385+
for (index = 0; index < collectionLength; index++) {
386386
key = (collection === collectionKeys) ? index : collectionKeys[index];
387387
value = collection[key];
388388
block = nextBlockOrder[index];
@@ -401,7 +401,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
401401
$animate.move(getBlockNodes(block.clone), null, jqLite(previousNode));
402402
}
403403
previousNode = getBlockEnd(block);
404-
updateScope(block.scope, index, valueIdentifier, value, keyIdentifier, key, arrayLength);
404+
updateScope(block.scope, index, valueIdentifier, value, keyIdentifier, key, collectionLength);
405405
} else {
406406
// new item which we don't know about
407407
$transclude(function ngRepeatTransclude(clone, scope) {
@@ -415,7 +415,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
415415
// by a directive with templateUrl when its template arrives.
416416
block.clone = clone;
417417
nextBlockMap[block.id] = block;
418-
updateScope(block.scope, index, valueIdentifier, value, keyIdentifier, key, arrayLength);
418+
updateScope(block.scope, index, valueIdentifier, value, keyIdentifier, key, collectionLength);
419419
});
420420
}
421421
}

0 commit comments

Comments
 (0)