Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an accidentally quadratic reduce(concat) in FlattenedNodesObserver #5739

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## Unreleased
- FlattenedNodesObserver.getFlattenedNodes was accidentally quadratic if given a non-slot node. Found by @mvanbem-goog.

## [v3.5.1](https://github.com/Polymer/polymer/tree/v3.5.1) (2022-06-03)
- [ci skip] bump to 3.5.1 ([commit](https://github.com/Polymer/polymer/commit/2cbb3d2b))

Expand Down
15 changes: 9 additions & 6 deletions lib/utils/flattened-nodes-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,17 @@ export let FlattenedNodesObserver = class {
node = /** @type {!HTMLSlotElement} */(node); // eslint-disable-line no-self-assign
return wrapped.assignedNodes({flatten: true});
} else {
return Array.from(wrapped.childNodes).map((node) => {
const results = [];
for (let i = 0; i < wrapped.childNodes.length; i++) {
const node = wrapped.childNodes[i];
if (isSlot(node)) {
node = /** @type {!HTMLSlotElement} */(node); // eslint-disable-line no-self-assign
return wrap(node).assignedNodes({flatten: true});
const slotNode = /** @type {!HTMLSlotElement} */ (node);
results.push(...wrap(slotNode).assignedNodes({ flatten: true }));
} else {
return [node];
results.push(node);
}
}).reduce((a, b) => a.concat(b), []);
}
return results;
}
}

Expand Down Expand Up @@ -311,4 +314,4 @@ export let FlattenedNodesObserver = class {
}
}

};
};
Loading