@@ -683,7 +683,10 @@ class StringAssembler {
683683/**
684684 * A custom made StringBuffer
685685 */
686- exports . stringAssembler = ( ) => new StringAssembler ( ) ;
686+ exports . stringAssembler = ( ) => {
687+ warnDeprecated ( 'Changeset.stringAssembler() is deprecated; build a string manually instead' ) ;
688+ return new StringAssembler ( ) ;
689+ } ;
687690
688691/**
689692 * Class to iterate and modify texts which have several lines. It is used for applying Changesets on
@@ -1080,7 +1083,7 @@ exports.applyToText = (cs, str) => {
10801083 assert ( str . length === unpacked . oldLen , 'mismatched apply: ' , str . length , ' / ' , unpacked . oldLen ) ;
10811084 const bankIter = exports . stringIterator ( unpacked . charBank ) ;
10821085 const strIter = exports . stringIterator ( str ) ;
1083- const assem = exports . stringAssembler ( ) ;
1086+ let assem = '' ;
10841087 for ( const op of new exports . OpIter ( unpacked . ops ) ) {
10851088 switch ( op . opcode ) {
10861089 case '+' :
@@ -1089,7 +1092,7 @@ exports.applyToText = (cs, str) => {
10891092 if ( op . lines !== bankIter . peek ( op . chars ) . split ( '\n' ) . length - 1 ) {
10901093 throw new Error ( `newline count is wrong in op +; cs:${ cs } and text:${ str } ` ) ;
10911094 }
1092- assem . append ( bankIter . take ( op . chars ) ) ;
1095+ assem += bankIter . take ( op . chars ) ;
10931096 break ;
10941097 case '-' :
10951098 // op is - and op.lines 0: no newlines must be in the deleted string
@@ -1105,12 +1108,12 @@ exports.applyToText = (cs, str) => {
11051108 if ( op . lines !== strIter . peek ( op . chars ) . split ( '\n' ) . length - 1 ) {
11061109 throw new Error ( `newline count is wrong in op =; cs:${ cs } and text:${ str } ` ) ;
11071110 }
1108- assem . append ( strIter . take ( op . chars ) ) ;
1111+ assem += strIter . take ( op . chars ) ;
11091112 break ;
11101113 }
11111114 }
1112- assem . append ( strIter . take ( strIter . remaining ( ) ) ) ;
1113- return assem . toString ( ) ;
1115+ assem += strIter . take ( strIter . remaining ( ) ) ;
1116+ return assem ;
11141117} ;
11151118
11161119/**
@@ -1182,12 +1185,11 @@ exports.composeAttributes = (att1, att2, resultIsMutation, pool) => {
11821185 }
11831186 return '' ;
11841187 } ) ;
1185- const buf = exports . stringAssembler ( ) ;
1188+ let buf = '' ;
11861189 for ( const att of [ ...atts ] . sort ( ( a , b ) => ( a [ 0 ] > b [ 0 ] ) - ( a [ 0 ] < b [ 0 ] ) ) ) {
1187- buf . append ( '*' ) ;
1188- buf . append ( exports . numToString ( pool . putAttrib ( att ) ) ) ;
1190+ buf += `*${ exports . numToString ( pool . putAttrib ( att ) ) } ` ;
11891191 }
1190- return buf . toString ( ) ;
1192+ return buf ;
11911193} ;
11921194
11931195/**
@@ -1395,7 +1397,7 @@ exports.compose = (cs1, cs2, pool) => {
13951397 const len3 = unpacked2 . newLen ;
13961398 const bankIter1 = exports . stringIterator ( unpacked1 . charBank ) ;
13971399 const bankIter2 = exports . stringIterator ( unpacked2 . charBank ) ;
1398- const bankAssem = exports . stringAssembler ( ) ;
1400+ let bankAssem = '' ;
13991401
14001402 const newOps = applyZip ( unpacked1 . ops , unpacked2 . ops , ( op1 , op2 ) => {
14011403 const op1code = op1 . opcode ;
@@ -1405,16 +1407,12 @@ exports.compose = (cs1, cs2, pool) => {
14051407 }
14061408 const opOut = slicerZipperFunc ( op1 , op2 , pool ) ;
14071409 if ( opOut . opcode === '+' ) {
1408- if ( op2code === '+' ) {
1409- bankAssem . append ( bankIter2 . take ( opOut . chars ) ) ;
1410- } else {
1411- bankAssem . append ( bankIter1 . take ( opOut . chars ) ) ;
1412- }
1410+ bankAssem += ( op2code === '+' ? bankIter2 : bankIter1 ) . take ( opOut . chars ) ;
14131411 }
14141412 return opOut ;
14151413 } ) ;
14161414
1417- return exports . pack ( len1 , len3 , newOps , bankAssem . toString ( ) ) ;
1415+ return exports . pack ( len1 , len3 , newOps , bankAssem ) ;
14181416} ;
14191417
14201418/**
@@ -1781,7 +1779,7 @@ exports.Builder = class {
17811779 this . _oldLen = oldLen ;
17821780 this . _ops = [ ] ;
17831781 this . _packed = null ;
1784- this . _charBank = exports . stringAssembler ( ) ;
1782+ this . _charBank = '' ;
17851783 }
17861784
17871785 /**
@@ -1807,7 +1805,7 @@ exports.Builder = class {
18071805 insert ( text , attribs , pool ) {
18081806 this . _packed = null ;
18091807 this . _ops . push ( ...opsFromText ( '+' , text , attribs , pool ) ) ;
1810- this . _charBank . append ( text ) ;
1808+ this . _charBank += text ;
18111809 return this ;
18121810 }
18131811
@@ -1828,7 +1826,7 @@ exports.Builder = class {
18281826 lengthChange = yield * exports . canonicalizeOps ( this . _ops , true ) ;
18291827 } ) . call ( this ) ) ;
18301828 const newLen = this . _oldLen + lengthChange ;
1831- this . _packed = exports . pack ( this . _oldLen , newLen , serializedOps , this . _charBank . toString ( ) ) ;
1829+ this . _packed = exports . pack ( this . _oldLen , newLen , serializedOps , this . _charBank ) ;
18321830 }
18331831 return this . _packed ;
18341832 }
@@ -1986,20 +1984,20 @@ exports.inverse = (cs, lines, alines, pool) => {
19861984
19871985 const nextText = ( numChars ) => {
19881986 let len = 0 ;
1989- const assem = exports . stringAssembler ( ) ;
1987+ let assem = '' ;
19901988 const firstString = linesGet ( curLine ) . substring ( curChar ) ;
19911989 len += firstString . length ;
1992- assem . append ( firstString ) ;
1990+ assem += firstString ;
19931991
19941992 let lineNum = curLine + 1 ;
19951993 while ( len < numChars ) {
19961994 const nextString = linesGet ( lineNum ) ;
19971995 len += nextString . length ;
1998- assem . append ( nextString ) ;
1996+ assem += nextString ;
19991997 lineNum ++ ;
20001998 }
20011999
2002- return assem . toString ( ) . substring ( 0 , numChars ) ;
2000+ return assem . substring ( 0 , numChars ) ;
20032001 } ;
20042002
20052003 const cachedStrFunc = ( func ) => {
@@ -2212,12 +2210,9 @@ const followAttributes = (att1, att2, pool) => {
22122210 return '' ;
22132211 } ) ;
22142212 // we've only removed attributes, so they're already sorted
2215- const buf = exports . stringAssembler ( ) ;
2216- for ( const att of atts ) {
2217- buf . append ( '*' ) ;
2218- buf . append ( exports . numToString ( pool . putAttrib ( att ) ) ) ;
2219- }
2220- return buf . toString ( ) ;
2213+ let buf = '' ;
2214+ for ( const att of atts ) buf += `*${ exports . numToString ( pool . putAttrib ( att ) ) } ` ;
2215+ return buf ;
22212216} ;
22222217
22232218exports . exportedForTestingOnly = {
0 commit comments