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

Commit

Permalink
perf(Angular): only create new collection in getBlockNodes if the blo…
Browse files Browse the repository at this point in the history
…ck has changed

Closes #9899
  • Loading branch information
jbedard authored and petebacondarwin committed Sep 7, 2015
1 parent 159bbf1 commit 0202663
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/Angular.js
Expand Up @@ -1779,22 +1779,24 @@ function getter(obj, path, bindFnToScope) {
/**
* Return the DOM siblings between the first and last node in the given array.
* @param {Array} array like object
* @returns {jqLite} jqLite collection containing the nodes
* @returns {Array} the inputted object or a jqLite collection containing the nodes
*/
function getBlockNodes(nodes) {
// TODO(perf): just check if all items in `nodes` are siblings and if they are return the original
// collection, otherwise update the original collection.
// TODO(perf): update `nodes` instead of creating a new object?
var node = nodes[0];
var endNode = nodes[nodes.length - 1];
var blockNodes = [node];
var blockNodes;

do {
node = node.nextSibling;
if (!node) break;
blockNodes.push(node);
} while (node !== endNode);
for (var i = 1; node !== endNode && (node = node.nextSibling); i++) {
if (blockNodes || nodes[i] !== node) {
if (!blockNodes) {
blockNodes = jqLite(slice.call(nodes, 0, i));
}
blockNodes.push(node);
}
}

return jqLite(blockNodes);
return blockNodes || nodes;
}


Expand Down

0 comments on commit 0202663

Please sign in to comment.