@@ -731,7 +731,11 @@ class StringAssembler {
731731/**
732732 * @returns {StringAssembler }
733733 */
734- exports . stringAssembler = ( ) => new StringAssembler ( ) ;
734+ exports . stringAssembler = ( ) => {
735+ padutils . warnDeprecated (
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/**
@@ -1920,7 +1920,7 @@ class Builder {
19201920 constructor ( oldLen ) {
19211921 this . _oldLen = oldLen ;
19221922 this . _ops = [ ] ;
1923- this . _charBank = new StringAssembler ( ) ;
1923+ this . _charBank = '' ;
19241924 }
19251925
19261926 /**
@@ -1966,7 +1966,7 @@ class Builder {
19661966 */
19671967 insert ( text , attribs = '' , pool = null ) {
19681968 this . _ops . push ( ...opsFromText ( '+' , text , attribs , pool ) ) ;
1969- this . _charBank . append ( text ) ;
1969+ this . _charBank += text ;
19701970 return this ;
19711971 }
19721972
@@ -1998,7 +1998,7 @@ class Builder {
19981998 oldLen : this . _oldLen ,
19991999 newLen : this . _oldLen + lengthChange ,
20002000 ops : serializedOps ,
2001- charBank : this . _charBank . toString ( ) ,
2001+ charBank : this . _charBank ,
20022002 } ;
20032003 }
20042004
@@ -2181,20 +2181,20 @@ exports.inverse = (cs, lines, alines, pool) => {
21812181
21822182 const nextText = ( numChars ) => {
21832183 let len = 0 ;
2184- const assem = new StringAssembler ( ) ;
2184+ let assem = '' ;
21852185 const firstString = linesGet ( curLine ) . substring ( curChar ) ;
21862186 len += firstString . length ;
2187- assem . append ( firstString ) ;
2187+ assem += firstString ;
21882188
21892189 let lineNum = curLine + 1 ;
21902190 while ( len < numChars ) {
21912191 const nextString = linesGet ( lineNum ) ;
21922192 len += nextString . length ;
2193- assem . append ( nextString ) ;
2193+ assem += nextString ;
21942194 lineNum ++ ;
21952195 }
21962196
2197- return assem . toString ( ) . substring ( 0 , numChars ) ;
2197+ return assem . substring ( 0 , numChars ) ;
21982198 } ;
21992199
22002200 const cachedStrFunc = ( func ) => {
@@ -2407,12 +2407,9 @@ const followAttributes = (att1, att2, pool) => {
24072407 return '' ;
24082408 } ) ;
24092409 // we've only removed attributes, so they're already sorted
2410- const buf = new StringAssembler ( ) ;
2411- for ( const att of atts ) {
2412- buf . append ( '*' ) ;
2413- buf . append ( exports . numToString ( pool . putAttrib ( att ) ) ) ;
2414- }
2415- return buf . toString ( ) ;
2410+ let buf = '' ;
2411+ for ( const att of atts ) buf += `*${ exports . numToString ( pool . putAttrib ( att ) ) } ` ;
2412+ return buf ;
24162413} ;
24172414
24182415exports . exportedForTestingOnly = {
0 commit comments