@@ -358,7 +358,7 @@ class OpAssembler {
358358 * @param {boolean } finalize - If truthy, omits the final op if it is an attributeless keep op.
359359 * @yields {Op} The squashed operations.
360360 */
361- const squashOps = function * ( ops , finalize ) {
361+ exports . squashOps = function * ( ops , finalize ) {
362362 let prevOp = new exports . Op ( ) ;
363363 // If we get, for example, insertions [xxx\n,yyy], those don't merge, but if we get
364364 // [xxx\n,yyy,zzz\n], that merges to [xxx\nyyyzzz\n]. This variable stores the length of yyy and
@@ -417,7 +417,7 @@ class MergingOpAssembler {
417417 }
418418
419419 _serialize ( finalize ) {
420- this . _serialized = exports . serializeOps ( squashOps ( this . _ops , finalize ) ) ;
420+ this . _serialized = exports . serializeOps ( exports . squashOps ( this . _ops , finalize ) ) ;
421421 }
422422
423423 clear ( ) {
@@ -459,14 +459,14 @@ const canonicalizeOps = function* (ops, finalize) {
459459 let lengthChange = 0 ;
460460
461461 const flushPlusMinus = function * ( ) {
462- yield * squashOps ( minusOps , false ) ;
462+ yield * exports . squashOps ( minusOps , false ) ;
463463 minusOps = [ ] ;
464- yield * squashOps ( plusOps , false ) ;
464+ yield * exports . squashOps ( plusOps , false ) ;
465465 plusOps = [ ] ;
466466 } ;
467467
468468 const flushKeeps = function * ( finalize ) {
469- yield * squashOps ( keepOps , finalize ) ;
469+ yield * exports . squashOps ( keepOps , finalize ) ;
470470 keepOps = [ ] ;
471471 } ;
472472
@@ -619,9 +619,13 @@ exports.checkRep = (cs) => {
619619exports . smartOpAssembler = ( ) => new SmartOpAssembler ( ) ;
620620
621621/**
622+ * @deprecated Use `squashOps` with `serializeOps` instead.
622623 * @returns {MergingOpAssembler }
623624 */
624- exports . mergingOpAssembler = ( ) => new MergingOpAssembler ( ) ;
625+ exports . mergingOpAssembler = ( ) => {
626+ warnDeprecated ( 'Changeset.mergingOpAssembler() is deprecated; use Changeset.squashOps() instead' ) ;
627+ return new MergingOpAssembler ( ) ;
628+ } ;
625629
626630/**
627631 * @deprecated Use `serializeOps` instead.
@@ -1332,28 +1336,26 @@ exports.mutateAttributionLines = (cs, lines, pool) => {
13321336 if ( ! lineIter || ! lineIter . hasNext ( ) ) return new exports . Op ( ) ;
13331337 return lineIter . next ( ) ;
13341338 } ;
1335- let lineAssem = null ;
1339+ let lineOps = null ;
13361340
13371341 const outputMutOp = ( op ) => {
1338- if ( ! lineAssem ) {
1339- lineAssem = new MergingOpAssembler ( ) ;
1340- }
1341- lineAssem . append ( op ) ;
1342+ if ( lineOps == null ) lineOps = [ ] ;
1343+ lineOps . push ( op ) ;
13421344 if ( op . lines <= 0 ) return ;
13431345 assert ( op . lines === 1 , "Can't have op.lines of " , op . lines , ' in attribution lines' ) ;
13441346 // ship it to the mut
1345- mut . insert ( lineAssem . toString ( ) , 1 ) ;
1346- lineAssem = null ;
1347+ mut . insert ( exports . serializeOps ( exports . squashOps ( lineOps , false ) ) , 1 ) ;
1348+ lineOps = null ;
13471349 } ;
13481350
13491351 let csOp = new exports . Op ( ) ;
13501352 let attOp = new exports . Op ( ) ;
13511353 while ( csOp . opcode || csIter . hasNext ( ) || attOp . opcode || isNextMutOp ( ) ) {
13521354 if ( ! csOp . opcode && csIter . hasNext ( ) ) csOp = csIter . next ( ) ;
1353- if ( ( ! csOp . opcode ) && ( ! attOp . opcode ) && ( ! lineAssem ) && ( ! ( lineIter && lineIter . hasNext ( ) ) ) ) {
1355+ if ( ! csOp . opcode && ! attOp . opcode && lineOps == null && ! ( lineIter && lineIter . hasNext ( ) ) ) {
13541356 break ; // done
13551357 } else if ( csOp . opcode === '=' && csOp . lines > 0 && ( ! csOp . attribs ) &&
1356- ( ! attOp . opcode ) && ( ! lineAssem ) && ( ! ( lineIter && lineIter . hasNext ( ) ) ) ) {
1358+ ! attOp . opcode && lineOps == null && ! ( lineIter && lineIter . hasNext ( ) ) ) {
13571359 // skip multiple lines; this is what makes small changes not order of the document size
13581360 mut . skipLines ( csOp . lines ) ;
13591361 csOp . opcode = '' ;
@@ -1377,7 +1379,7 @@ exports.mutateAttributionLines = (cs, lines, pool) => {
13771379 }
13781380 }
13791381
1380- assert ( ! lineAssem , `line assembler not finished:${ cs } ` ) ;
1382+ assert ( lineOps == null , `line assembler not finished:${ cs } ` ) ;
13811383 mut . close ( ) ;
13821384} ;
13831385
@@ -1387,24 +1389,20 @@ exports.mutateAttributionLines = (cs, lines, pool) => {
13871389 * @param {string[] } theAlines - collection of Attribution lines
13881390 * @returns {string } joined Attribution lines
13891391 */
1390- exports . joinAttributionLines = ( theAlines ) => {
1391- const assem = new MergingOpAssembler ( ) ;
1392- for ( const aline of theAlines ) {
1393- for ( const op of new exports . OpIter ( aline ) ) assem . append ( op ) ;
1394- }
1395- return assem . toString ( ) ;
1396- } ;
1392+ exports . joinAttributionLines = ( theAlines ) => exports . serializeOps ( exports . squashOps ( ( function * ( ) {
1393+ for ( const aline of theAlines ) yield * new exports . OpIter ( aline ) ;
1394+ } ) ( ) , false ) ) ;
13971395
13981396exports . splitAttributionLines = ( attrOps , text ) => {
1399- const assem = new MergingOpAssembler ( ) ;
1397+ let ops = [ ] ;
14001398 const lines = [ ] ;
14011399 let pos = 0 ;
14021400
14031401 const appendOp = ( op ) => {
1404- assem . append ( op ) ;
1402+ ops . push ( op ) ;
14051403 if ( op . lines > 0 ) {
1406- lines . push ( assem . toString ( ) ) ;
1407- assem . clear ( ) ;
1404+ lines . push ( exports . serializeOps ( exports . squashOps ( ops , false ) ) ) ;
1405+ ops = [ ] ;
14081406 }
14091407 pos += op . chars ;
14101408 } ;
0 commit comments