Moved ElementsSidebar dfs to iterator in Container

This commit is contained in:
Siklos 2022-08-02 23:31:08 +02:00
parent 0dc078493a
commit 8792c8bee5
2 changed files with 22 additions and 16 deletions

View file

@ -14,26 +14,13 @@ interface IElementsSidebarProps {
export class ElementsSidebar extends React.Component<IElementsSidebarProps> {
public iterateChilds(handleContainer: (container: Container) => void): React.ReactNode {
const root = this.props.MainContainer;
if (!root) {
if (!this.props.MainContainer) {
return null;
}
const queue = [root];
const visited = new Set([root]);
while (queue.length > 0) {
const container = queue.pop() as Container;
const it = this.props.MainContainer.MakeIterator();
for (const container of it) {
handleContainer(container);
// if this reverse() gets costly, replace it by a simple for
container.props.children.reverse().forEach((child) => {
if (visited.has(child)) {
return;
}
visited.add(child);
queue.push(child);
});
}
}