@@ -38,10 +38,15 @@ class ConcatSource extends Source {
3838 */
3939 this . _children = [ ] ;
4040
41- for ( const item of args ) {
41+ // Indexed loops avoid the iterator-protocol overhead `for...of`
42+ // pays per element. Hot during webpack's emit when many
43+ // ConcatSources are constructed/flattened.
44+ for ( let i = 0 , l = args . length ; i < l ; i ++ ) {
45+ const item = args [ i ] ;
4246 if ( item instanceof ConcatSource ) {
43- for ( const child of item . _children ) {
44- this . _children . push ( child ) ;
47+ const children = item . _children ;
48+ for ( let j = 0 , jl = children . length ; j < jl ; j ++ ) {
49+ this . _children . push ( children [ j ] ) ;
4550 }
4651 } else {
4752 this . _children . push ( item ) ;
@@ -69,8 +74,9 @@ class ConcatSource extends Source {
6974 */
7075 add ( item ) {
7176 if ( item instanceof ConcatSource ) {
72- for ( const child of item . _children ) {
73- this . _children . push ( child ) ;
77+ const children = item . _children ;
78+ for ( let i = 0 , l = children . length ; i < l ; i ++ ) {
79+ this . _children . push ( children [ i ] ) ;
7480 }
7581 } else {
7682 this . _children . push ( item ) ;
@@ -83,8 +89,8 @@ class ConcatSource extends Source {
8389 * @returns {void }
8490 */
8591 addAllSkipOptimizing ( items ) {
86- for ( const item of items ) {
87- this . _children . push ( item ) ;
92+ for ( let i = 0 , l = items . length ; i < l ; i ++ ) {
93+ this . _children . push ( items [ i ] ) ;
8894 }
8995 }
9096
@@ -197,7 +203,10 @@ class ConcatSource extends Source {
197203 const finalSource = Boolean ( options && options . finalSource ) ;
198204 let code = "" ;
199205 let needToCloseMapping = false ;
200- for ( const item of /** @type {Source[] } */ ( this . _children ) ) {
206+ const children = /** @type {Source[] } */ ( this . _children ) ;
207+ const childCount = children . length ;
208+ for ( let ci = 0 ; ci < childCount ; ci ++ ) {
209+ const item = children [ ci ] ;
201210 /** @type {number[] } */
202211 const sourceIndexMapping = [ ] ;
203212 /** @type {number[] } */
@@ -391,7 +400,9 @@ class ConcatSource extends Source {
391400 newChildren . push ( currentRawSources ) ;
392401 }
393402 } ;
394- for ( const child of this . _children ) {
403+ const children = this . _children ;
404+ for ( let ci = 0 , cl = children . length ; ci < cl ; ci ++ ) {
405+ const child = children [ ci ] ;
395406 if ( typeof child === "string" ) {
396407 if ( currentString === undefined ) {
397408 currentString = child ;
0 commit comments