mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-06-18 12:14:04 +08:00
perf(ngRepeat): simplify code and remove duplicate array.length access
minimal perf gain (~2ms)
This commit is contained in:
@@ -310,13 +310,13 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
|
||||
// Same as lastBlockMap but it has the current state. It will become the
|
||||
// lastBlockMap on the next iteration.
|
||||
nextBlockMap = createMap(),
|
||||
arrayLength,
|
||||
collectionLength,
|
||||
key, value, // key/value of iteration
|
||||
trackById,
|
||||
trackByIdFn,
|
||||
collectionKeys,
|
||||
block, // last object information {scope, element, id}
|
||||
nextBlockOrder = [],
|
||||
nextBlockOrder,
|
||||
elementsToRemove;
|
||||
|
||||
if (aliasAs) {
|
||||
@@ -338,11 +338,11 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
|
||||
collectionKeys.sort();
|
||||
}
|
||||
|
||||
arrayLength = collectionKeys.length;
|
||||
collectionLength = collectionKeys.length;
|
||||
nextBlockOrder = new Array(collectionLength);
|
||||
|
||||
// locate existing items
|
||||
length = nextBlockOrder.length = collectionKeys.length;
|
||||
for (index = 0; index < length; index++) {
|
||||
for (index = 0; index < collectionLength; index++) {
|
||||
key = (collection === collectionKeys) ? index : collectionKeys[index];
|
||||
value = collection[key];
|
||||
trackById = trackByIdFn(key, value, index);
|
||||
@@ -382,7 +382,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
|
||||
}
|
||||
|
||||
// we are not using forEach for perf reasons (trying to avoid #call)
|
||||
for (index = 0, length = collectionKeys.length; index < length; index++) {
|
||||
for (index = 0; index < collectionLength; index++) {
|
||||
key = (collection === collectionKeys) ? index : collectionKeys[index];
|
||||
value = collection[key];
|
||||
block = nextBlockOrder[index];
|
||||
@@ -401,7 +401,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
|
||||
$animate.move(getBlockNodes(block.clone), null, jqLite(previousNode));
|
||||
}
|
||||
previousNode = getBlockEnd(block);
|
||||
updateScope(block.scope, index, valueIdentifier, value, keyIdentifier, key, arrayLength);
|
||||
updateScope(block.scope, index, valueIdentifier, value, keyIdentifier, key, collectionLength);
|
||||
} else {
|
||||
// new item which we don't know about
|
||||
$transclude(function ngRepeatTransclude(clone, scope) {
|
||||
@@ -415,7 +415,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
|
||||
// by a directive with templateUrl when its template arrives.
|
||||
block.clone = clone;
|
||||
nextBlockMap[block.id] = block;
|
||||
updateScope(block.scope, index, valueIdentifier, value, keyIdentifier, key, arrayLength);
|
||||
updateScope(block.scope, index, valueIdentifier, value, keyIdentifier, key, collectionLength);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user