Skip to content

Commit 77f0881

Browse files
committed
perf(Angular): only create new collection in getBlockNodes if the block has changed
1 parent 0f7bcfd commit 77f0881

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/Angular.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -1549,22 +1549,24 @@ function getter(obj, path, bindFnToScope) {
15491549
/**
15501550
* Return the DOM siblings between the first and last node in the given array.
15511551
* @param {Array} array like object
1552-
* @returns {jqLite} jqLite collection containing the nodes
1552+
* @returns {Array} the inputted object or a jqLite collection containing the nodes
15531553
*/
15541554
function getBlockNodes(nodes) {
1555-
// TODO(perf): just check if all items in `nodes` are siblings and if they are return the original
1556-
// collection, otherwise update the original collection.
1555+
// TODO(perf): update the original collection instead of creating a new one
15571556
var node = nodes[0];
15581557
var endNode = nodes[nodes.length - 1];
1559-
var blockNodes = [node];
1558+
var blockNodes = nodes;
15601559

1561-
do {
1562-
node = node.nextSibling;
1563-
if (!node) break;
1564-
blockNodes.push(node);
1565-
} while (node !== endNode);
1560+
for (var i = 1; node && node !== endNode; i++) {
1561+
if (blockNodes[i] !== (node = node.nextSibling)) {
1562+
if (blockNodes === nodes) {
1563+
blockNodes = jqLite(slice.call(nodes, 0, i));
1564+
}
1565+
blockNodes.push(node);
1566+
}
1567+
}
15661568

1567-
return jqLite(blockNodes);
1569+
return blockNodes;
15681570
}
15691571

15701572

0 commit comments

Comments
 (0)