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

Improved performance of the 'getSubNodes()' utility #11475

Merged
merged 1 commit into from
Mar 28, 2022
Merged
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
6 changes: 4 additions & 2 deletions packages/ckeditor5-watchdog/src/utils/getsubnodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ export default function getSubNodes( head, excludedProperties = new Set() ) {

// Nodes are stored to prevent infinite looping.
const subNodes = new Set();
let nodeIndex = 0;

while ( nodes.length > 0 ) {
const node = nodes.shift();
while ( nodes.length > nodeIndex ) {
// Incrementing the iterator is much faster than changing size of the array with Array.prototype.shift().
const node = nodes[ nodeIndex++ ];

if ( subNodes.has( node ) || shouldNodeBeSkipped( node ) || excludedProperties.has( node ) ) {
continue;
Expand Down