@@ -738,7 +738,10 @@ class StringAssembler {
738738/**
739739 * @returns {StringAssembler }
740740 */
741- exports . stringAssembler = ( ) => new StringAssembler ( ) ;
741+ exports . stringAssembler = ( ) => {
742+ warnDeprecated ( 'Changeset.stringAssembler() is deprecated; build a string manually instead' ) ;
743+ return new StringAssembler ( ) ;
744+ } ;
742745
743746/**
744747 * @typedef {object } StringArrayLike
@@ -1167,7 +1170,7 @@ exports.applyToText = (cs, str) => {
11671170 assert ( str . length === unpacked . oldLen , `mismatched apply: ${ str . length } / ${ unpacked . oldLen } ` ) ;
11681171 const bankIter = exports . stringIterator ( unpacked . charBank ) ;
11691172 const strIter = exports . stringIterator ( str ) ;
1170- const assem = new StringAssembler ( ) ;
1173+ let assem = '' ;
11711174 for ( const op of exports . deserializeOps ( unpacked . ops ) ) {
11721175 switch ( op . opcode ) {
11731176 case '+' :
@@ -1176,7 +1179,7 @@ exports.applyToText = (cs, str) => {
11761179 if ( op . lines !== bankIter . peek ( op . chars ) . split ( '\n' ) . length - 1 ) {
11771180 throw new Error ( `newline count is wrong in op +; cs:${ cs } and text:${ str } ` ) ;
11781181 }
1179- assem . append ( bankIter . take ( op . chars ) ) ;
1182+ assem += bankIter . take ( op . chars ) ;
11801183 break ;
11811184 case '-' :
11821185 // op is - and op.lines 0: no newlines must be in the deleted string
@@ -1192,12 +1195,12 @@ exports.applyToText = (cs, str) => {
11921195 if ( op . lines !== strIter . peek ( op . chars ) . split ( '\n' ) . length - 1 ) {
11931196 throw new Error ( `newline count is wrong in op =; cs:${ cs } and text:${ str } ` ) ;
11941197 }
1195- assem . append ( strIter . take ( op . chars ) ) ;
1198+ assem += strIter . take ( op . chars ) ;
11961199 break ;
11971200 }
11981201 }
1199- assem . append ( strIter . take ( strIter . remaining ( ) ) ) ;
1200- return assem . toString ( ) ;
1202+ assem += strIter . take ( strIter . remaining ( ) ) ;
1203+ return assem ;
12011204} ;
12021205
12031206/**
@@ -1281,12 +1284,11 @@ exports.composeAttributes = (att1, att2, resultIsMutation, pool) => {
12811284 }
12821285 return '' ;
12831286 } ) ;
1284- const buf = new StringAssembler ( ) ;
1287+ let buf = '' ;
12851288 for ( const att of sortAttribs ( [ ...atts ] ) ) {
1286- buf . append ( '*' ) ;
1287- buf . append ( exports . numToString ( pool . putAttrib ( att ) ) ) ;
1289+ buf += `*${ exports . numToString ( pool . putAttrib ( att ) ) } ` ;
12881290 }
1289- return buf . toString ( ) ;
1291+ return buf ;
12901292} ;
12911293
12921294/**
@@ -1506,7 +1508,7 @@ exports.compose = (cs1, cs2, pool) => {
15061508 const len3 = unpacked2 . newLen ;
15071509 const bankIter1 = exports . stringIterator ( unpacked1 . charBank ) ;
15081510 const bankIter2 = exports . stringIterator ( unpacked2 . charBank ) ;
1509- const bankAssem = new StringAssembler ( ) ;
1511+ let bankAssem = '' ;
15101512
15111513 const newOps = applyZip ( unpacked1 . ops , unpacked2 . ops , ( op1 , op2 ) => {
15121514 const op1code = op1 . opcode ;
@@ -1516,16 +1518,12 @@ exports.compose = (cs1, cs2, pool) => {
15161518 }
15171519 const opOut = slicerZipperFunc ( op1 , op2 , pool ) ;
15181520 if ( opOut . opcode === '+' ) {
1519- if ( op2code === '+' ) {
1520- bankAssem . append ( bankIter2 . take ( opOut . chars ) ) ;
1521- } else {
1522- bankAssem . append ( bankIter1 . take ( opOut . chars ) ) ;
1523- }
1521+ bankAssem += ( op2code === '+' ? bankIter2 : bankIter1 ) . take ( opOut . chars ) ;
15241522 }
15251523 return opOut ;
15261524 } ) ;
15271525
1528- return exports . pack ( len1 , len3 , newOps , bankAssem . toString ( ) ) ;
1526+ return exports . pack ( len1 , len3 , newOps , bankAssem ) ;
15291527} ;
15301528
15311529/**
@@ -1938,7 +1936,7 @@ class Builder {
19381936 constructor ( oldLen ) {
19391937 this . _oldLen = oldLen ;
19401938 this . _ops = [ ] ;
1941- this . _charBank = new StringAssembler ( ) ;
1939+ this . _charBank = '' ;
19421940 }
19431941
19441942 /**
@@ -1983,7 +1981,7 @@ class Builder {
19831981 */
19841982 insert ( text , attribs = '' , pool = null ) {
19851983 this . _ops . push ( ...opsFromText ( '+' , text , attribs , pool ) ) ;
1986- this . _charBank . append ( text ) ;
1984+ this . _charBank += text ;
19871985 return this ;
19881986 }
19891987
@@ -2015,7 +2013,7 @@ class Builder {
20152013 oldLen : this . _oldLen ,
20162014 newLen : this . _oldLen + lengthChange ,
20172015 ops : serializedOps ,
2018- charBank : this . _charBank . toString ( ) ,
2016+ charBank : this . _charBank ,
20192017 } ;
20202018 }
20212019
@@ -2181,20 +2179,20 @@ exports.inverse = (cs, lines, alines, pool) => {
21812179
21822180 const nextText = ( numChars ) => {
21832181 let len = 0 ;
2184- const assem = new StringAssembler ( ) ;
2182+ let assem = '' ;
21852183 const firstString = linesGet ( curLine ) . substring ( curChar ) ;
21862184 len += firstString . length ;
2187- assem . append ( firstString ) ;
2185+ assem += firstString ;
21882186
21892187 let lineNum = curLine + 1 ;
21902188 while ( len < numChars ) {
21912189 const nextString = linesGet ( lineNum ) ;
21922190 len += nextString . length ;
2193- assem . append ( nextString ) ;
2191+ assem += nextString ;
21942192 lineNum ++ ;
21952193 }
21962194
2197- return assem . toString ( ) . substring ( 0 , numChars ) ;
2195+ return assem . substring ( 0 , numChars ) ;
21982196 } ;
21992197
22002198 const cachedStrFunc = ( func ) => {
@@ -2407,12 +2405,9 @@ const followAttributes = (att1, att2, pool) => {
24072405 return '' ;
24082406 } ) ;
24092407 // 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 ( ) ;
2408+ let buf = '' ;
2409+ for ( const att of atts ) buf += `*${ exports . numToString ( pool . putAttrib ( att ) ) } ` ;
2410+ return buf ;
24162411} ;
24172412
24182413exports . exportedForTestingOnly = {
0 commit comments