@@ -730,7 +730,10 @@ class StringAssembler {
730730/**
731731 * @returns {StringAssembler }
732732 */
733- exports . stringAssembler = ( ) => new StringAssembler ( ) ;
733+ exports . stringAssembler = ( ) => {
734+ warnDeprecated ( 'Changeset.stringAssembler() is deprecated; build a string manually instead' ) ;
735+ return new StringAssembler ( ) ;
736+ } ;
734737
735738/**
736739 * Class to iterate and modify texts which have several lines. It is used for applying Changesets on
@@ -1142,7 +1145,7 @@ exports.applyToText = (cs, str) => {
11421145 assert ( str . length === unpacked . oldLen , 'mismatched apply: ' , str . length , ' / ' , unpacked . oldLen ) ;
11431146 const bankIter = exports . stringIterator ( unpacked . charBank ) ;
11441147 const strIter = exports . stringIterator ( str ) ;
1145- const assem = new StringAssembler ( ) ;
1148+ let assem = '' ;
11461149 for ( const op of new exports . OpIter ( unpacked . ops ) ) {
11471150 switch ( op . opcode ) {
11481151 case '+' :
@@ -1151,7 +1154,7 @@ exports.applyToText = (cs, str) => {
11511154 if ( op . lines !== bankIter . peek ( op . chars ) . split ( '\n' ) . length - 1 ) {
11521155 throw new Error ( `newline count is wrong in op +; cs:${ cs } and text:${ str } ` ) ;
11531156 }
1154- assem . append ( bankIter . take ( op . chars ) ) ;
1157+ assem += bankIter . take ( op . chars ) ;
11551158 break ;
11561159 case '-' :
11571160 // op is - and op.lines 0: no newlines must be in the deleted string
@@ -1167,12 +1170,12 @@ exports.applyToText = (cs, str) => {
11671170 if ( op . lines !== strIter . peek ( op . chars ) . split ( '\n' ) . length - 1 ) {
11681171 throw new Error ( `newline count is wrong in op =; cs:${ cs } and text:${ str } ` ) ;
11691172 }
1170- assem . append ( strIter . take ( op . chars ) ) ;
1173+ assem += strIter . take ( op . chars ) ;
11711174 break ;
11721175 }
11731176 }
1174- assem . append ( strIter . take ( strIter . remaining ( ) ) ) ;
1175- return assem . toString ( ) ;
1177+ assem += strIter . take ( strIter . remaining ( ) ) ;
1178+ return assem ;
11761179} ;
11771180
11781181/**
@@ -1247,12 +1250,11 @@ exports.composeAttributes = (att1, att2, resultIsMutation, pool) => {
12471250 }
12481251 return '' ;
12491252 } ) ;
1250- const buf = new StringAssembler ( ) ;
1253+ let buf = '' ;
12511254 for ( const att of [ ...atts ] . sort ( ( a , b ) => ( a [ 0 ] > b [ 0 ] ) - ( a [ 0 ] < b [ 0 ] ) ) ) {
1252- buf . append ( '*' ) ;
1253- buf . append ( exports . numToString ( pool . putAttrib ( att ) ) ) ;
1255+ buf += `*${ exports . numToString ( pool . putAttrib ( att ) ) } ` ;
12541256 }
1255- return buf . toString ( ) ;
1257+ return buf ;
12561258} ;
12571259
12581260/**
@@ -1468,7 +1470,7 @@ exports.compose = (cs1, cs2, pool) => {
14681470 const len3 = unpacked2 . newLen ;
14691471 const bankIter1 = exports . stringIterator ( unpacked1 . charBank ) ;
14701472 const bankIter2 = exports . stringIterator ( unpacked2 . charBank ) ;
1471- const bankAssem = new StringAssembler ( ) ;
1473+ let bankAssem = '' ;
14721474
14731475 const newOps = applyZip ( unpacked1 . ops , unpacked2 . ops , ( op1 , op2 ) => {
14741476 const op1code = op1 . opcode ;
@@ -1478,16 +1480,12 @@ exports.compose = (cs1, cs2, pool) => {
14781480 }
14791481 const opOut = slicerZipperFunc ( op1 , op2 , pool ) ;
14801482 if ( opOut . opcode === '+' ) {
1481- if ( op2code === '+' ) {
1482- bankAssem . append ( bankIter2 . take ( opOut . chars ) ) ;
1483- } else {
1484- bankAssem . append ( bankIter1 . take ( opOut . chars ) ) ;
1485- }
1483+ bankAssem += ( op2code === '+' ? bankIter2 : bankIter1 ) . take ( opOut . chars ) ;
14861484 }
14871485 return opOut ;
14881486 } ) ;
14891487
1490- return exports . pack ( len1 , len3 , newOps , bankAssem . toString ( ) ) ;
1488+ return exports . pack ( len1 , len3 , newOps , bankAssem ) ;
14911489} ;
14921490
14931491/**
@@ -1902,7 +1900,7 @@ exports.Builder = class {
19021900 constructor ( oldLen ) {
19031901 this . _oldLen = oldLen ;
19041902 this . _ops = [ ] ;
1905- this . _charBank = new StringAssembler ( ) ;
1903+ this . _charBank = '' ;
19061904 }
19071905
19081906 /**
@@ -1925,7 +1923,7 @@ exports.Builder = class {
19251923
19261924 insert ( text , attribs , pool ) {
19271925 this . _ops . push ( ...opsFromText ( '+' , text , attribs , pool ) ) ;
1928- this . _charBank . append ( text ) ;
1926+ this . _charBank += text ;
19291927 return this ;
19301928 }
19311929
@@ -1944,7 +1942,7 @@ exports.Builder = class {
19441942 lengthChange = yield * exports . canonicalizeOps ( this . _ops , true ) ;
19451943 } ) . call ( this ) ) ;
19461944 const newLen = this . _oldLen + lengthChange ;
1947- return exports . pack ( this . _oldLen , newLen , serializedOps , this . _charBank . toString ( ) ) ;
1945+ return exports . pack ( this . _oldLen , newLen , serializedOps , this . _charBank ) ;
19481946 }
19491947} ;
19501948
@@ -2103,20 +2101,20 @@ exports.inverse = (cs, lines, alines, pool) => {
21032101
21042102 const nextText = ( numChars ) => {
21052103 let len = 0 ;
2106- const assem = new StringAssembler ( ) ;
2104+ let assem = '' ;
21072105 const firstString = linesGet ( curLine ) . substring ( curChar ) ;
21082106 len += firstString . length ;
2109- assem . append ( firstString ) ;
2107+ assem += firstString ;
21102108
21112109 let lineNum = curLine + 1 ;
21122110 while ( len < numChars ) {
21132111 const nextString = linesGet ( lineNum ) ;
21142112 len += nextString . length ;
2115- assem . append ( nextString ) ;
2113+ assem += nextString ;
21162114 lineNum ++ ;
21172115 }
21182116
2119- return assem . toString ( ) . substring ( 0 , numChars ) ;
2117+ return assem . substring ( 0 , numChars ) ;
21202118 } ;
21212119
21222120 const cachedStrFunc = ( func ) => {
@@ -2329,12 +2327,9 @@ const followAttributes = (att1, att2, pool) => {
23292327 return '' ;
23302328 } ) ;
23312329 // we've only removed attributes, so they're already sorted
2332- const buf = new StringAssembler ( ) ;
2333- for ( const att of atts ) {
2334- buf . append ( '*' ) ;
2335- buf . append ( exports . numToString ( pool . putAttrib ( att ) ) ) ;
2336- }
2337- return buf . toString ( ) ;
2330+ let buf = '' ;
2331+ for ( const att of atts ) buf += `*${ exports . numToString ( pool . putAttrib ( att ) ) } ` ;
2332+ return buf ;
23382333} ;
23392334
23402335exports . exportedForTestingOnly = {
0 commit comments