@@ -731,7 +731,11 @@ class StringAssembler {
731731/**
732732 * @returns {StringAssembler }
733733 */
734- exports . stringAssembler = ( ) => new StringAssembler ( ) ;
734+ exports . stringAssembler = ( ) => {
735+ padutils . warnWithStack (
736+ 'Changeset.stringAssembler() is deprecated; build a string manually instead' ) ;
737+ return new StringAssembler ( ) ;
738+ } ;
735739
736740/**
737741 * @typedef {object } StringArrayLike
@@ -1158,7 +1162,7 @@ exports.applyToText = (cs, str) => {
11581162 assert ( str . length === unpacked . oldLen , `mismatched apply: ${ str . length } / ${ unpacked . oldLen } ` ) ;
11591163 const bankIter = exports . stringIterator ( unpacked . charBank ) ;
11601164 const strIter = exports . stringIterator ( str ) ;
1161- const assem = new StringAssembler ( ) ;
1165+ let assem = '' ;
11621166 for ( const op of exports . deserializeOps ( unpacked . ops ) ) {
11631167 switch ( op . opcode ) {
11641168 case '+' :
@@ -1167,7 +1171,7 @@ exports.applyToText = (cs, str) => {
11671171 if ( op . lines !== bankIter . peek ( op . chars ) . split ( '\n' ) . length - 1 ) {
11681172 throw new Error ( `newline count is wrong in op +; cs:${ cs } and text:${ str } ` ) ;
11691173 }
1170- assem . append ( bankIter . take ( op . chars ) ) ;
1174+ assem += bankIter . take ( op . chars ) ;
11711175 break ;
11721176 case '-' :
11731177 // op is - and op.lines 0: no newlines must be in the deleted string
@@ -1183,12 +1187,12 @@ exports.applyToText = (cs, str) => {
11831187 if ( op . lines !== strIter . peek ( op . chars ) . split ( '\n' ) . length - 1 ) {
11841188 throw new Error ( `newline count is wrong in op =; cs:${ cs } and text:${ str } ` ) ;
11851189 }
1186- assem . append ( strIter . take ( op . chars ) ) ;
1190+ assem += strIter . take ( op . chars ) ;
11871191 break ;
11881192 }
11891193 }
1190- assem . append ( strIter . take ( strIter . remaining ( ) ) ) ;
1191- return assem . toString ( ) ;
1194+ assem += strIter . take ( strIter . remaining ( ) ) ;
1195+ return assem ;
11921196} ;
11931197
11941198/**
@@ -1477,7 +1481,7 @@ exports.compose = (cs1, cs2, pool) => {
14771481 const len3 = unpacked2 . newLen ;
14781482 const bankIter1 = exports . stringIterator ( unpacked1 . charBank ) ;
14791483 const bankIter2 = exports . stringIterator ( unpacked2 . charBank ) ;
1480- const bankAssem = new StringAssembler ( ) ;
1484+ let bankAssem = '' ;
14811485
14821486 const newOps = applyZip ( unpacked1 . ops , unpacked2 . ops , ( op1 , op2 ) => {
14831487 const op1code = op1 . opcode ;
@@ -1487,16 +1491,12 @@ exports.compose = (cs1, cs2, pool) => {
14871491 }
14881492 const opOut = slicerZipperFunc ( op1 , op2 , pool ) ;
14891493 if ( opOut . opcode === '+' ) {
1490- if ( op2code === '+' ) {
1491- bankAssem . append ( bankIter2 . take ( opOut . chars ) ) ;
1492- } else {
1493- bankAssem . append ( bankIter1 . take ( opOut . chars ) ) ;
1494- }
1494+ bankAssem += ( op2code === '+' ? bankIter2 : bankIter1 ) . take ( opOut . chars ) ;
14951495 }
14961496 return opOut ;
14971497 } ) ;
14981498
1499- return exports . pack ( len1 , len3 , newOps , bankAssem . toString ( ) ) ;
1499+ return exports . pack ( len1 , len3 , newOps , bankAssem ) ;
15001500} ;
15011501
15021502/**
@@ -1925,7 +1925,7 @@ class Builder {
19251925 constructor ( oldLen ) {
19261926 this . _oldLen = oldLen ;
19271927 this . _ops = [ ] ;
1928- this . _charBank = new StringAssembler ( ) ;
1928+ this . _charBank = '' ;
19291929 }
19301930
19311931 /**
@@ -1971,7 +1971,7 @@ class Builder {
19711971 */
19721972 insert ( text , attribs = '' , pool = null ) {
19731973 this . _ops . push ( ...opsFromText ( '+' , text , attribs , pool ) ) ;
1974- this . _charBank . append ( text ) ;
1974+ this . _charBank += text ;
19751975 return this ;
19761976 }
19771977
@@ -2003,7 +2003,7 @@ class Builder {
20032003 oldLen : this . _oldLen ,
20042004 newLen : this . _oldLen + lengthChange ,
20052005 ops : serializedOps ,
2006- charBank : this . _charBank . toString ( ) ,
2006+ charBank : this . _charBank ,
20072007 } ;
20082008 }
20092009
@@ -2186,20 +2186,20 @@ exports.inverse = (cs, lines, alines, pool) => {
21862186
21872187 const nextText = ( numChars ) => {
21882188 let len = 0 ;
2189- const assem = new StringAssembler ( ) ;
2189+ let assem = '' ;
21902190 const firstString = linesGet ( curLine ) . substring ( curChar ) ;
21912191 len += firstString . length ;
2192- assem . append ( firstString ) ;
2192+ assem += firstString ;
21932193
21942194 let lineNum = curLine + 1 ;
21952195 while ( len < numChars ) {
21962196 const nextString = linesGet ( lineNum ) ;
21972197 len += nextString . length ;
2198- assem . append ( nextString ) ;
2198+ assem += nextString ;
21992199 lineNum ++ ;
22002200 }
22012201
2202- return assem . toString ( ) . substring ( 0 , numChars ) ;
2202+ return assem . substring ( 0 , numChars ) ;
22032203 } ;
22042204
22052205 const cachedStrFunc = ( func ) => {
@@ -2412,12 +2412,9 @@ const followAttributes = (att1, att2, pool) => {
24122412 return '' ;
24132413 } ) ;
24142414 // we've only removed attributes, so they're already sorted
2415- const buf = new StringAssembler ( ) ;
2416- for ( const att of atts ) {
2417- buf . append ( '*' ) ;
2418- buf . append ( exports . numToString ( pool . putAttrib ( att ) ) ) ;
2419- }
2420- return buf . toString ( ) ;
2415+ let buf = '' ;
2416+ for ( const att of atts ) buf += `*${ exports . numToString ( pool . putAttrib ( att ) ) } ` ;
2417+ return buf ;
24212418} ;
24222419
24232420exports . exportedForTestingOnly = {
0 commit comments