Skip to content

Commit

Permalink
allocate iteration structures lazily
Browse files Browse the repository at this point in the history
(cherry picked from commit 2b46034)
  • Loading branch information
stefanpenner authored and chancancode committed Mar 14, 2017
1 parent bdb46eb commit 756c845
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/ember-metal/lib/meta.js
Expand Up @@ -281,26 +281,30 @@ export class Meta {

_forEachIn(key, subkey, fn) {
let pointer = this;
let seen = new EmptyObject();
let calls = [];
let seen;
let calls;
while (pointer !== undefined) {
let map = pointer[key];
if (map) {
seen = seen || new EmptyObject();
let innerMap = map[subkey];
if (innerMap) {
for (let innerKey in innerMap) {
if (!seen[innerKey]) {
seen[innerKey] = true;
calls = calls || [];
calls.push([innerKey, innerMap[innerKey]]);
}
}
}
}
pointer = pointer.parent;
}
for (let i = 0; i < calls.length; i++) {
let [innerKey, value] = calls[i];
fn(innerKey, value);
if (calls) {
for (let i = 0; i < calls.length; i++) {
let [innerKey, value] = calls[i];
fn(innerKey, value);
}
}
}

Expand Down

0 comments on commit 756c845

Please sign in to comment.