@@ -727,7 +727,11 @@ class StringAssembler {
727727/**
728728 * @returns {StringAssembler }
729729 */
730- exports . stringAssembler = ( ) => new StringAssembler ( ) ;
730+ exports . stringAssembler = ( ) => {
731+ padutils . warnWithStack (
732+ 'Changeset.stringAssembler() is deprecated; build a string manually instead' ) ;
733+ return new StringAssembler ( ) ;
734+ } ;
731735
732736/**
733737 * @typedef {object } StringArrayLike
@@ -1156,7 +1160,7 @@ exports.applyToText = (cs, str) => {
11561160 assert ( str . length === unpacked . oldLen , `mismatched apply: ${ str . length } / ${ unpacked . oldLen } ` ) ;
11571161 const bankIter = exports . stringIterator ( unpacked . charBank ) ;
11581162 const strIter = exports . stringIterator ( str ) ;
1159- const assem = new StringAssembler ( ) ;
1163+ let assem = '' ;
11601164 for ( const op of exports . deserializeOps ( unpacked . ops ) ) {
11611165 switch ( op . opcode ) {
11621166 case '+' :
@@ -1165,7 +1169,7 @@ exports.applyToText = (cs, str) => {
11651169 if ( op . lines !== bankIter . peek ( op . chars ) . split ( '\n' ) . length - 1 ) {
11661170 throw new Error ( `newline count is wrong in op +; cs:${ cs } and text:${ str } ` ) ;
11671171 }
1168- assem . append ( bankIter . take ( op . chars ) ) ;
1172+ assem += bankIter . take ( op . chars ) ;
11691173 break ;
11701174 case '-' :
11711175 // op is - and op.lines 0: no newlines must be in the deleted string
@@ -1181,12 +1185,12 @@ exports.applyToText = (cs, str) => {
11811185 if ( op . lines !== strIter . peek ( op . chars ) . split ( '\n' ) . length - 1 ) {
11821186 throw new Error ( `newline count is wrong in op =; cs:${ cs } and text:${ str } ` ) ;
11831187 }
1184- assem . append ( strIter . take ( op . chars ) ) ;
1188+ assem += strIter . take ( op . chars ) ;
11851189 break ;
11861190 }
11871191 }
1188- assem . append ( strIter . take ( strIter . remaining ( ) ) ) ;
1189- return assem . toString ( ) ;
1192+ assem += strIter . take ( strIter . remaining ( ) ) ;
1193+ return assem ;
11901194} ;
11911195
11921196/**
@@ -1475,7 +1479,7 @@ exports.compose = (cs1, cs2, pool) => {
14751479 const len3 = unpacked2 . newLen ;
14761480 const bankIter1 = exports . stringIterator ( unpacked1 . charBank ) ;
14771481 const bankIter2 = exports . stringIterator ( unpacked2 . charBank ) ;
1478- const bankAssem = new StringAssembler ( ) ;
1482+ let bankAssem = '' ;
14791483
14801484 const newOps = applyZip ( unpacked1 . ops , unpacked2 . ops , ( op1 , op2 ) => {
14811485 const op1code = op1 . opcode ;
@@ -1485,16 +1489,12 @@ exports.compose = (cs1, cs2, pool) => {
14851489 }
14861490 const opOut = slicerZipperFunc ( op1 , op2 , pool ) ;
14871491 if ( opOut . opcode === '+' ) {
1488- if ( op2code === '+' ) {
1489- bankAssem . append ( bankIter2 . take ( opOut . chars ) ) ;
1490- } else {
1491- bankAssem . append ( bankIter1 . take ( opOut . chars ) ) ;
1492- }
1492+ bankAssem += ( op2code === '+' ? bankIter2 : bankIter1 ) . take ( opOut . chars ) ;
14931493 }
14941494 return opOut ;
14951495 } ) ;
14961496
1497- return exports . pack ( len1 , len3 , newOps , bankAssem . toString ( ) ) ;
1497+ return exports . pack ( len1 , len3 , newOps , bankAssem ) ;
14981498} ;
14991499
15001500/**
@@ -1923,7 +1923,7 @@ class Builder {
19231923 constructor ( oldLen ) {
19241924 this . _oldLen = oldLen ;
19251925 this . _ops = [ ] ;
1926- this . _charBank = new StringAssembler ( ) ;
1926+ this . _charBank = '' ;
19271927 }
19281928
19291929 /**
@@ -1969,7 +1969,7 @@ class Builder {
19691969 */
19701970 insert ( text , attribs = '' , pool = null ) {
19711971 this . _ops . push ( ...opsFromText ( '+' , text , attribs , pool ) ) ;
1972- this . _charBank . append ( text ) ;
1972+ this . _charBank += text ;
19731973 return this ;
19741974 }
19751975
@@ -2001,7 +2001,7 @@ class Builder {
20012001 oldLen : this . _oldLen ,
20022002 newLen : this . _oldLen + lengthChange ,
20032003 ops : serializedOps ,
2004- charBank : this . _charBank . toString ( ) ,
2004+ charBank : this . _charBank ,
20052005 } ;
20062006 }
20072007
@@ -2184,20 +2184,20 @@ exports.inverse = (cs, lines, alines, pool) => {
21842184
21852185 const nextText = ( numChars ) => {
21862186 let len = 0 ;
2187- const assem = new StringAssembler ( ) ;
2187+ let assem = '' ;
21882188 const firstString = linesGet ( curLine ) . substring ( curChar ) ;
21892189 len += firstString . length ;
2190- assem . append ( firstString ) ;
2190+ assem += firstString ;
21912191
21922192 let lineNum = curLine + 1 ;
21932193 while ( len < numChars ) {
21942194 const nextString = linesGet ( lineNum ) ;
21952195 len += nextString . length ;
2196- assem . append ( nextString ) ;
2196+ assem += nextString ;
21972197 lineNum ++ ;
21982198 }
21992199
2200- return assem . toString ( ) . substring ( 0 , numChars ) ;
2200+ return assem . substring ( 0 , numChars ) ;
22012201 } ;
22022202
22032203 const cachedStrFunc = ( func ) => {
@@ -2410,12 +2410,9 @@ const followAttributes = (att1, att2, pool) => {
24102410 return '' ;
24112411 } ) ;
24122412 // we've only removed attributes, so they're already sorted
2413- const buf = new StringAssembler ( ) ;
2414- for ( const att of atts ) {
2415- buf . append ( '*' ) ;
2416- buf . append ( exports . numToString ( pool . putAttrib ( att ) ) ) ;
2417- }
2418- return buf . toString ( ) ;
2413+ let buf = '' ;
2414+ for ( const att of atts ) buf += `*${ exports . numToString ( pool . putAttrib ( att ) ) } ` ;
2415+ return buf ;
24192416} ;
24202417
24212418exports . exportedForTestingOnly = {
0 commit comments