8
0
Просмотр исходного кода

Changed: Used `WeakMap` to store indexes of next operations to transform in `transformSets`.

Szymon Cofalik 7 лет назад
Родитель
Сommit
bf591a77cd
1 измененных файлов с 8 добавлено и 12 удалено
  1. 8 12
      packages/ckeditor5-engine/src/model/operation/transform.js

+ 8 - 12
packages/ckeditor5-engine/src/model/operation/transform.js

@@ -79,8 +79,10 @@ export function transformSets( operationsA, operationsB, options ) {
 		return { operationsA, operationsB };
 	}
 
+	const nextTransformIndex = new WeakMap();
+
 	for ( const op of operationsA ) {
-		op.transformBy = 0;
+		nextTransformIndex.set( op, 0 );
 	}
 
 	const data = {
@@ -97,14 +99,14 @@ export function transformSets( operationsA, operationsB, options ) {
 	while ( i < operationsA.length ) {
 		const opA = operationsA[ i ];
 
-		const transformBy = opA.transformBy;
+		const transformByIndex = nextTransformIndex.get( opA );
 
-		if ( transformBy == operationsB.length ) {
+		if ( transformByIndex == operationsB.length ) {
 			i++;
 			continue;
 		}
 
-		const opB = operationsB[ transformBy ];
+		const opB = operationsB[ transformByIndex ];
 
 		if ( options.useContext ) {
 			updateRelations( context, opA, opB );
@@ -134,23 +136,17 @@ export function transformSets( operationsA, operationsB, options ) {
 			updateOriginalOperation( context, opB, newOpsB );
 		}
 
-		const newTransformBy = transformBy + newOpsB.length;
-
 		for ( const newOpA of newOpsA ) {
-			newOpA.transformBy = newTransformBy;
+			nextTransformIndex.set( newOpA, transformByIndex + newOpsB.length );
 		}
 
 		operationsA.splice( i, 1, ...newOpsA );
-		operationsB.splice( transformBy, 1, ...newOpsB );
+		operationsB.splice( transformByIndex, 1, ...newOpsB );
 
 		data.extraOpsA += newOpsA.length - 1;
 		data.extraOpsB += newOpsB.length - 1;
 	}
 
-	for ( const op of operationsA ) {
-		delete op.transformBy;
-	}
-
 	if ( options.padWithNoOps ) {
 		padWithNoOps( operationsA, data.extraOpsB - data.extraOpsA );
 		padWithNoOps( operationsB, data.extraOpsA - data.extraOpsB );