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

Commit 0202663

Browse files
jbedardpetebacondarwin
authored andcommittedSep 7, 2015
perf(Angular): only create new collection in getBlockNodes if the block has changed
Closes #9899
1 parent 159bbf1 commit 0202663

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
@@ -1779,22 +1779,24 @@ function getter(obj, path, bindFnToScope) {
17791779
/**
17801780
* Return the DOM siblings between the first and last node in the given array.
17811781
* @param {Array} array like object
1782-
* @returns {jqLite} jqLite collection containing the nodes
1782+
* @returns {Array} the inputted object or a jqLite collection containing the nodes
17831783
*/
17841784
function getBlockNodes(nodes) {
1785-
// TODO(perf): just check if all items in `nodes` are siblings and if they are return the original
1786-
// collection, otherwise update the original collection.
1785+
// TODO(perf): update `nodes` instead of creating a new object?
17871786
var node = nodes[0];
17881787
var endNode = nodes[nodes.length - 1];
1789-
var blockNodes = [node];
1788+
var blockNodes;
17901789

1791-
do {
1792-
node = node.nextSibling;
1793-
if (!node) break;
1794-
blockNodes.push(node);
1795-
} while (node !== endNode);
1790+
for (var i = 1; node !== endNode && (node = node.nextSibling); i++) {
1791+
if (blockNodes || nodes[i] !== node) {
1792+
if (!blockNodes) {
1793+
blockNodes = jqLite(slice.call(nodes, 0, i));
1794+
}
1795+
blockNodes.push(node);
1796+
}
1797+
}
17961798

1797-
return jqLite(blockNodes);
1799+
return blockNodes || nodes;
17981800
}
17991801

18001802

0 commit comments

Comments
 (0)