Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit e317177

Browse files
committed
perf(Angular): only create new collection in getBlockNodes if the block has changed
1 parent 28114fa commit e317177

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
@@ -1638,22 +1638,24 @@ function getter(obj, path, bindFnToScope) {
16381638
/**
16391639
* Return the DOM siblings between the first and last node in the given array.
16401640
* @param {Array} array like object
1641-
* @returns {jqLite} jqLite collection containing the nodes
1641+
* @returns {Array} the inputted object or a jqLite collection containing the nodes
16421642
*/
16431643
function getBlockNodes(nodes) {
1644-
// TODO(perf): just check if all items in `nodes` are siblings and if they are return the original
1645-
// collection, otherwise update the original collection.
1644+
// TODO(perf): update `nodes` instead of creating a new object?
16461645
var node = nodes[0];
16471646
var endNode = nodes[nodes.length - 1];
1648-
var blockNodes = [node];
1647+
var blockNodes;
16491648

1650-
do {
1651-
node = node.nextSibling;
1652-
if (!node) break;
1653-
blockNodes.push(node);
1654-
} while (node !== endNode);
1649+
for (var i = 1; node !== endNode && (node = node.nextSibling); i++) {
1650+
if (blockNodes || nodes[i] !== node) {
1651+
if (!blockNodes) {
1652+
blockNodes = jqLite(slice.call(nodes, 0, i));
1653+
}
1654+
blockNodes.push(node);
1655+
}
1656+
}
16551657

1656-
return jqLite(blockNodes);
1658+
return blockNodes || nodes;
16571659
}
16581660

16591661

0 commit comments

Comments
 (0)