@@ -737,7 +737,10 @@ class StringAssembler {
737737/**
738738 * @returns {StringAssembler }
739739 */
740- exports . stringAssembler = ( ) => new StringAssembler ( ) ;
740+ exports . stringAssembler = ( ) => {
741+ warnDeprecated ( 'Changeset.stringAssembler() is deprecated; build a string manually instead' ) ;
742+ return new StringAssembler ( ) ;
743+ } ;
741744
742745/**
743746 * @typedef {object } StringArrayLike
@@ -1166,7 +1169,7 @@ exports.applyToText = (cs, str) => {
11661169 assert ( str . length === unpacked . oldLen , `mismatched apply: ${ str . length } / ${ unpacked . oldLen } ` ) ;
11671170 const bankIter = exports . stringIterator ( unpacked . charBank ) ;
11681171 const strIter = exports . stringIterator ( str ) ;
1169- const assem = new StringAssembler ( ) ;
1172+ let assem = '' ;
11701173 for ( const op of exports . deserializeOps ( unpacked . ops ) ) {
11711174 switch ( op . opcode ) {
11721175 case '+' :
@@ -1175,7 +1178,7 @@ exports.applyToText = (cs, str) => {
11751178 if ( op . lines !== bankIter . peek ( op . chars ) . split ( '\n' ) . length - 1 ) {
11761179 throw new Error ( `newline count is wrong in op +; cs:${ cs } and text:${ str } ` ) ;
11771180 }
1178- assem . append ( bankIter . take ( op . chars ) ) ;
1181+ assem += bankIter . take ( op . chars ) ;
11791182 break ;
11801183 case '-' :
11811184 // op is - and op.lines 0: no newlines must be in the deleted string
@@ -1191,12 +1194,12 @@ exports.applyToText = (cs, str) => {
11911194 if ( op . lines !== strIter . peek ( op . chars ) . split ( '\n' ) . length - 1 ) {
11921195 throw new Error ( `newline count is wrong in op =; cs:${ cs } and text:${ str } ` ) ;
11931196 }
1194- assem . append ( strIter . take ( op . chars ) ) ;
1197+ assem += strIter . take ( op . chars ) ;
11951198 break ;
11961199 }
11971200 }
1198- assem . append ( strIter . take ( strIter . remaining ( ) ) ) ;
1199- return assem . toString ( ) ;
1201+ assem += strIter . take ( strIter . remaining ( ) ) ;
1202+ return assem ;
12001203} ;
12011204
12021205/**
@@ -1280,12 +1283,11 @@ exports.composeAttributes = (att1, att2, resultIsMutation, pool) => {
12801283 }
12811284 return '' ;
12821285 } ) ;
1283- const buf = new StringAssembler ( ) ;
1286+ let buf = '' ;
12841287 for ( const att of sortAttribs ( [ ...atts ] ) ) {
1285- buf . append ( '*' ) ;
1286- buf . append ( exports . numToString ( pool . putAttrib ( att ) ) ) ;
1288+ buf += `*${ exports . numToString ( pool . putAttrib ( att ) ) } ` ;
12871289 }
1288- return buf . toString ( ) ;
1290+ return buf ;
12891291} ;
12901292
12911293/**
@@ -1514,7 +1516,7 @@ exports.compose = (cs1, cs2, pool) => {
15141516 const len3 = unpacked2 . newLen ;
15151517 const bankIter1 = exports . stringIterator ( unpacked1 . charBank ) ;
15161518 const bankIter2 = exports . stringIterator ( unpacked2 . charBank ) ;
1517- const bankAssem = new StringAssembler ( ) ;
1519+ let bankAssem = '' ;
15181520
15191521 const newOps = applyZip ( unpacked1 . ops , unpacked2 . ops , ( op1 , op2 ) => {
15201522 const op1code = op1 . opcode ;
@@ -1524,16 +1526,12 @@ exports.compose = (cs1, cs2, pool) => {
15241526 }
15251527 const opOut = slicerZipperFunc ( op1 , op2 , pool ) ;
15261528 if ( opOut . opcode === '+' ) {
1527- if ( op2code === '+' ) {
1528- bankAssem . append ( bankIter2 . take ( opOut . chars ) ) ;
1529- } else {
1530- bankAssem . append ( bankIter1 . take ( opOut . chars ) ) ;
1531- }
1529+ bankAssem += ( op2code === '+' ? bankIter2 : bankIter1 ) . take ( opOut . chars ) ;
15321530 }
15331531 return opOut ;
15341532 } ) ;
15351533
1536- return exports . pack ( len1 , len3 , newOps , bankAssem . toString ( ) ) ;
1534+ return exports . pack ( len1 , len3 , newOps , bankAssem ) ;
15371535} ;
15381536
15391537/**
@@ -1946,7 +1944,7 @@ class Builder {
19461944 constructor ( oldLen ) {
19471945 this . _oldLen = oldLen ;
19481946 this . _ops = [ ] ;
1949- this . _charBank = new StringAssembler ( ) ;
1947+ this . _charBank = '' ;
19501948 }
19511949
19521950 /**
@@ -1991,7 +1989,7 @@ class Builder {
19911989 */
19921990 insert ( text , attribs = '' , pool = null ) {
19931991 this . _ops . push ( ...opsFromText ( '+' , text , attribs , pool ) ) ;
1994- this . _charBank . append ( text ) ;
1992+ this . _charBank += text ;
19951993 return this ;
19961994 }
19971995
@@ -2023,7 +2021,7 @@ class Builder {
20232021 oldLen : this . _oldLen ,
20242022 newLen : this . _oldLen + lengthChange ,
20252023 ops : serializedOps ,
2026- charBank : this . _charBank . toString ( ) ,
2024+ charBank : this . _charBank ,
20272025 } ;
20282026 }
20292027
@@ -2201,20 +2199,20 @@ exports.inverse = (cs, lines, alines, pool) => {
22012199
22022200 const nextText = ( numChars ) => {
22032201 let len = 0 ;
2204- const assem = new StringAssembler ( ) ;
2202+ let assem = '' ;
22052203 const firstString = linesGet ( curLine ) . substring ( curChar ) ;
22062204 len += firstString . length ;
2207- assem . append ( firstString ) ;
2205+ assem += firstString ;
22082206
22092207 let lineNum = curLine + 1 ;
22102208 while ( len < numChars ) {
22112209 const nextString = linesGet ( lineNum ) ;
22122210 len += nextString . length ;
2213- assem . append ( nextString ) ;
2211+ assem += nextString ;
22142212 lineNum ++ ;
22152213 }
22162214
2217- return assem . toString ( ) . substring ( 0 , numChars ) ;
2215+ return assem . substring ( 0 , numChars ) ;
22182216 } ;
22192217
22202218 const cachedStrFunc = ( func ) => {
@@ -2427,12 +2425,9 @@ const followAttributes = (att1, att2, pool) => {
24272425 return '' ;
24282426 } ) ;
24292427 // we've only removed attributes, so they're already sorted
2430- const buf = new StringAssembler ( ) ;
2431- for ( const att of atts ) {
2432- buf . append ( '*' ) ;
2433- buf . append ( exports . numToString ( pool . putAttrib ( att ) ) ) ;
2434- }
2435- return buf . toString ( ) ;
2428+ let buf = '' ;
2429+ for ( const att of atts ) buf += `*${ exports . numToString ( pool . putAttrib ( att ) ) } ` ;
2430+ return buf ;
24362431} ;
24372432
24382433exports . exportedForTestingOnly = {
0 commit comments