@@ -743,7 +743,11 @@ class StringAssembler {
743743/**
744744 * @returns {StringAssembler }
745745 */
746- exports . stringAssembler = ( ) => new StringAssembler ( ) ;
746+ exports . stringAssembler = ( ) => {
747+ padutils . warnWithStack (
748+ 'Changeset.stringAssembler() is deprecated; build a string manually instead' ) ;
749+ return new StringAssembler ( ) ;
750+ } ;
747751
748752/**
749753 * @typedef {object } StringArrayLike
@@ -1172,7 +1176,7 @@ exports.applyToText = (cs, str) => {
11721176 assert ( str . length === unpacked . oldLen , `mismatched apply: ${ str . length } / ${ unpacked . oldLen } ` ) ;
11731177 const bankIter = exports . stringIterator ( unpacked . charBank ) ;
11741178 const strIter = exports . stringIterator ( str ) ;
1175- const assem = new StringAssembler ( ) ;
1179+ let assem = '' ;
11761180 for ( const op of exports . deserializeOps ( unpacked . ops ) ) {
11771181 switch ( op . opcode ) {
11781182 case '+' :
@@ -1181,7 +1185,7 @@ exports.applyToText = (cs, str) => {
11811185 if ( op . lines !== bankIter . 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 ( bankIter . take ( op . chars ) ) ;
1188+ assem += bankIter . take ( op . chars ) ;
11851189 break ;
11861190 case '-' :
11871191 // op is - and op.lines 0: no newlines must be in the deleted string
@@ -1197,12 +1201,12 @@ exports.applyToText = (cs, str) => {
11971201 if ( op . lines !== strIter . peek ( op . chars ) . split ( '\n' ) . length - 1 ) {
11981202 throw new Error ( `newline count is wrong in op =; cs:${ cs } and text:${ str } ` ) ;
11991203 }
1200- assem . append ( strIter . take ( op . chars ) ) ;
1204+ assem += strIter . take ( op . chars ) ;
12011205 break ;
12021206 }
12031207 }
1204- assem . append ( strIter . take ( strIter . remaining ( ) ) ) ;
1205- return assem . toString ( ) ;
1208+ assem += strIter . take ( strIter . remaining ( ) ) ;
1209+ return assem ;
12061210} ;
12071211
12081212/**
@@ -1491,7 +1495,7 @@ exports.compose = (cs1, cs2, pool) => {
14911495 const len3 = unpacked2 . newLen ;
14921496 const bankIter1 = exports . stringIterator ( unpacked1 . charBank ) ;
14931497 const bankIter2 = exports . stringIterator ( unpacked2 . charBank ) ;
1494- const bankAssem = new StringAssembler ( ) ;
1498+ let bankAssem = '' ;
14951499
14961500 const newOps = applyZip ( unpacked1 . ops , unpacked2 . ops , ( op1 , op2 ) => {
14971501 const op1code = op1 . opcode ;
@@ -1501,16 +1505,12 @@ exports.compose = (cs1, cs2, pool) => {
15011505 }
15021506 const opOut = slicerZipperFunc ( op1 , op2 , pool ) ;
15031507 if ( opOut . opcode === '+' ) {
1504- if ( op2code === '+' ) {
1505- bankAssem . append ( bankIter2 . take ( opOut . chars ) ) ;
1506- } else {
1507- bankAssem . append ( bankIter1 . take ( opOut . chars ) ) ;
1508- }
1508+ bankAssem += ( op2code === '+' ? bankIter2 : bankIter1 ) . take ( opOut . chars ) ;
15091509 }
15101510 return opOut ;
15111511 } ) ;
15121512
1513- return exports . pack ( len1 , len3 , newOps , bankAssem . toString ( ) ) ;
1513+ return exports . pack ( len1 , len3 , newOps , bankAssem ) ;
15141514} ;
15151515
15161516/**
@@ -1939,7 +1939,7 @@ class Builder {
19391939 constructor ( oldLen ) {
19401940 this . _oldLen = oldLen ;
19411941 this . _ops = [ ] ;
1942- this . _charBank = new StringAssembler ( ) ;
1942+ this . _charBank = '' ;
19431943 }
19441944
19451945 /**
@@ -1985,7 +1985,7 @@ class Builder {
19851985 */
19861986 insert ( text , attribs = '' , pool = null ) {
19871987 this . _ops . push ( ...opsFromText ( '+' , text , attribs , pool ) ) ;
1988- this . _charBank . append ( text ) ;
1988+ this . _charBank += text ;
19891989 return this ;
19901990 }
19911991
@@ -2017,7 +2017,7 @@ class Builder {
20172017 oldLen : this . _oldLen ,
20182018 newLen : this . _oldLen + lengthChange ,
20192019 ops : serializedOps ,
2020- charBank : this . _charBank . toString ( ) ,
2020+ charBank : this . _charBank ,
20212021 } ;
20222022 }
20232023
@@ -2200,20 +2200,20 @@ exports.inverse = (cs, lines, alines, pool) => {
22002200
22012201 const nextText = ( numChars ) => {
22022202 let len = 0 ;
2203- const assem = new StringAssembler ( ) ;
2203+ let assem = '' ;
22042204 const firstString = linesGet ( curLine ) . substring ( curChar ) ;
22052205 len += firstString . length ;
2206- assem . append ( firstString ) ;
2206+ assem += firstString ;
22072207
22082208 let lineNum = curLine + 1 ;
22092209 while ( len < numChars ) {
22102210 const nextString = linesGet ( lineNum ) ;
22112211 len += nextString . length ;
2212- assem . append ( nextString ) ;
2212+ assem += nextString ;
22132213 lineNum ++ ;
22142214 }
22152215
2216- return assem . toString ( ) . substring ( 0 , numChars ) ;
2216+ return assem . substring ( 0 , numChars ) ;
22172217 } ;
22182218
22192219 const cachedStrFunc = ( func ) => {
@@ -2426,12 +2426,9 @@ const followAttributes = (att1, att2, pool) => {
24262426 return '' ;
24272427 } ) ;
24282428 // we've only removed attributes, so they're already sorted
2429- const buf = new StringAssembler ( ) ;
2430- for ( const att of atts ) {
2431- buf . append ( '*' ) ;
2432- buf . append ( exports . numToString ( pool . putAttrib ( att ) ) ) ;
2433- }
2434- return buf . toString ( ) ;
2429+ let buf = '' ;
2430+ for ( const att of atts ) buf += `*${ exports . numToString ( pool . putAttrib ( att ) ) } ` ;
2431+ return buf ;
24352432} ;
24362433
24372434exports . exportedForTestingOnly = {
0 commit comments