瀏覽代碼

Remove unnecessary loop.

Dominik Szczepaniak 6 年之前
父節點
當前提交
da56abb40d
共有 1 個文件被更改,包括 6 次插入12 次删除
  1. 6 12
      packages/ckeditor5-engine/src/model/operation/transform.js

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

@@ -155,14 +155,14 @@ export function transformSets( operationsA, operationsB, options ) {
 	operationsA = operationsA.slice();
 	operationsB = operationsB.slice();
 
-	// If one of sets is empty there is simply nothing to transform, so return sets as they are.
-	if ( operationsA.length == 0 || operationsB.length == 0 ) {
-		const originalOperations = new Map();
+	const contextFactory = new ContextFactory( options.document, options.useRelations, options.forceWeakRemove );
+	contextFactory.setOriginalOperations( operationsA );
+	contextFactory.setOriginalOperations( operationsB );
 
-		for ( const operation of operationsA.concat( operationsB ) ) {
-			originalOperations.set( operation, operation );
-		}
+	const originalOperations = contextFactory.originalOperations;
 
+	// If one of sets is empty there is simply nothing to transform, so return sets as they are.
+	if ( operationsA.length == 0 || operationsB.length == 0 ) {
 		return { operationsA, operationsB, originalOperations };
 	}
 	//
@@ -311,10 +311,6 @@ export function transformSets( operationsA, operationsB, options ) {
 		originalOperationsBCount: operationsB.length
 	};
 
-	const contextFactory = new ContextFactory( options.document, options.useRelations, options.forceWeakRemove );
-	contextFactory.setOriginalOperations( operationsA );
-	contextFactory.setOriginalOperations( operationsB );
-
 	// Index of currently transformed operation `a`.
 	let i = 0;
 
@@ -376,8 +372,6 @@ export function transformSets( operationsA, operationsB, options ) {
 		padWithNoOps( operationsB, brokenOperationsACount - brokenOperationsBCount );
 	}
 
-	const originalOperations = contextFactory.originalOperations;
-
 	// Finally, update base versions of transformed operations.
 	updateBaseVersions( operationsA, data.nextBaseVersionB );
 	updateBaseVersions( operationsB, data.nextBaseVersionA );