Skip to content

Commit

Permalink
Merge pull request #11475 from ckeditor/cf/4302
Browse files Browse the repository at this point in the history
Other: Improved performance of the `getSubNodes()` utility of `Watchdog`.
  • Loading branch information
Reinmar committed Mar 28, 2022
2 parents 085b29b + 8c195fd commit ee63f39
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/ckeditor5-watchdog/src/utils/getsubnodes.js
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

0 comments on commit ee63f39

Please sign in to comment.