Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit b52db48

Browse files
authored
Merge pull request #165 from ckeditor/i/6581
Other: Improved performance of processing (loading) long lists. Closes ckeditor/ckeditor5#6581.
2 parents 35e70a8 + 68eb4d4 commit b52db48

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/converters.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -649,30 +649,35 @@ export function modelChangePostFixer( model, writer ) {
649649
return applied;
650650

651651
function _addListToFix( position ) {
652-
const prev = position.nodeBefore;
652+
const previousNode = position.nodeBefore;
653653

654-
if ( !prev || !prev.is( 'listItem' ) ) {
654+
if ( !previousNode || !previousNode.is( 'listItem' ) ) {
655655
const item = position.nodeAfter;
656656

657657
if ( item && item.is( 'listItem' ) ) {
658658
itemToListHead.set( item, item );
659659
}
660660
} else {
661-
let listHead = prev;
661+
let listHead = previousNode;
662662

663663
if ( itemToListHead.has( listHead ) ) {
664664
return;
665665
}
666666

667-
while ( listHead.previousSibling && listHead.previousSibling.is( 'listItem' ) ) {
668-
listHead = listHead.previousSibling;
667+
for (
668+
// Cache previousSibling and reuse for performance reasons. See #6581.
669+
let previousSibling = listHead.previousSibling;
670+
previousSibling && previousSibling.is( 'listItem' );
671+
previousSibling = listHead.previousSibling
672+
) {
673+
listHead = previousSibling;
669674

670675
if ( itemToListHead.has( listHead ) ) {
671676
return;
672677
}
673678
}
674679

675-
itemToListHead.set( position.nodeBefore, listHead );
680+
itemToListHead.set( previousNode, listHead );
676681
}
677682
}
678683

0 commit comments

Comments
 (0)