Skip to content

Commit

Permalink
Update iterateCursor (ampproject#19309)
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell authored and Enriqe committed Nov 28, 2018
1 parent 0d168c1 commit 86d88d2
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,18 +632,16 @@ export function templateContentClone(template) {
}

/**
* Iterate over an array-like. Some collections like NodeList are
* lazily evaluated in some browsers, and accessing `length` forces full
* evaluation. We can improve performance by iterating until an element is
* `undefined` to avoid checking the `length` property.
* Test cases: https://jsperf.com/iterating-over-collections-of-elements
* Iterate over an array-like.
* Test cases: https://jsbench.github.io/#33a883c12f8c75cd5e62bdf12359b8e0
* @param {!IArrayLike<T>} iterable
* @param {function(T, number)} cb
* @template T
*/
export function iterateCursor(iterable, cb) {
for (let i = 0, value; (value = iterable[i]) !== undefined; i++) {
cb(value, i);
const {length} = iterable;
for (let i = 0; i < length; i++) {
cb(iterable[i], i);
}
}

Expand Down

0 comments on commit 86d88d2

Please sign in to comment.