@@ -21,6 +21,27 @@ const sortByIdentifier = (a, b) => {
2121 return 0 ;
2222} ;
2323
24+ const getFrozenArray = set => Object . freeze ( Array . from ( this ) ) ;
25+
26+ const getModulesIdent = set => {
27+ set . sort ( ) ;
28+ let str = "" ;
29+ set . forEach ( m => {
30+ str += m . identifier ( ) + "#" ;
31+ } ) ;
32+ return str ;
33+ } ;
34+
35+ const getArray = set => Array . from ( set ) ;
36+
37+ const getModulesSize = set => {
38+ let count = 0 ;
39+ for ( const module of set ) {
40+ count += module . size ( ) ;
41+ }
42+ return count ;
43+ } ;
44+
2445class Chunk {
2546
2647 constructor ( name , module , loc ) {
@@ -65,7 +86,7 @@ class Chunk {
6586 * @return {Array } - an array containing the chunks
6687 */
6788 getChunks ( ) {
68- return Array . from ( this . _chunks ) ;
89+ return this . _chunks . getCachedInfo ( getArray ) ;
6990 }
7091
7192 getNumberOfChunks ( ) {
@@ -80,7 +101,7 @@ class Chunk {
80101 * @return {Array } - an array containing the parents
81102 */
82103 getParents ( ) {
83- return Array . from ( this . _parents ) ;
104+ return this . _parents . getCachedInfo ( getArray ) ;
84105 }
85106
86107 setParents ( newParents ) {
@@ -109,7 +130,7 @@ class Chunk {
109130 * @return {Array } - an array containing the blocks
110131 */
111132 getBlocks ( ) {
112- return Array . from ( this . _blocks ) ;
133+ return this . _blocks . getCachedInfo ( getArray ) ;
113134 }
114135
115136 setBlocks ( newBlocks ) {
@@ -269,16 +290,11 @@ class Chunk {
269290 }
270291
271292 getModules ( ) {
272- return Array . from ( this . _modules ) ;
293+ return this . _modules . getCachedInfo ( getArray ) ;
273294 }
274295
275296 getModulesIdent ( ) {
276- this . _modules . sort ( ) ;
277- let str = "" ;
278- this . _modules . forEach ( m => {
279- str += m . identifier ( ) + "#" ;
280- } ) ;
281- return str ;
297+ return this . _modules . getOrderIndependentCachedInfo ( getModulesIdent ) ;
282298 }
283299
284300 remove ( reason ) {
@@ -452,11 +468,7 @@ class Chunk {
452468 }
453469
454470 modulesSize ( ) {
455- let count = 0 ;
456- for ( const module of this . _modules ) {
457- count += module . size ( ) ;
458- }
459- return count ;
471+ return this . _modules . getOrderIndependentCachedInfo ( getModulesSize ) ;
460472 }
461473
462474 size ( options ) {
@@ -543,7 +555,7 @@ class Chunk {
543555Object . defineProperty ( Chunk . prototype , "modules" , {
544556 configurable : false ,
545557 get : util . deprecate ( function ( ) {
546- return this . _modules . getFrozenArray ( ) ;
558+ return this . _modules . getCachedInfo ( getFrozenArray ) ;
547559 } , "Chunk.modules is deprecated. Use Chunk.getNumberOfModules/mapModules/forEachModule/containsModule instead." ) ,
548560 set : util . deprecate ( function ( value ) {
549561 this . setModules ( value ) ;
@@ -553,7 +565,7 @@ Object.defineProperty(Chunk.prototype, "modules", {
553565Object . defineProperty ( Chunk . prototype , "chunks" , {
554566 configurable : false ,
555567 get : util . deprecate ( function ( ) {
556- return this . _chunks . getFrozenArray ( ) ;
568+ return this . _chunks . getCachedInfo ( getFrozenArray ) ;
557569 } , "Chunk.chunks: Use Chunk.getChunks() instead" ) ,
558570 set ( ) {
559571 throw new Error ( "Readonly. Use Chunk.addChunk/removeChunk/getChunks to access/modify chunks." ) ;
@@ -563,7 +575,7 @@ Object.defineProperty(Chunk.prototype, "chunks", {
563575Object . defineProperty ( Chunk . prototype , "parents" , {
564576 configurable : false ,
565577 get : util . deprecate ( function ( ) {
566- return this . _parents . getFrozenArray ( ) ;
578+ return this . _parents . getCachedInfo ( getFrozenArray ) ;
567579 } , "Chunk.parents: Use Chunk.getParents() instead" ) ,
568580 set : util . deprecate ( function ( value ) {
569581 this . setParents ( value ) ;
@@ -573,7 +585,7 @@ Object.defineProperty(Chunk.prototype, "parents", {
573585Object . defineProperty ( Chunk . prototype , "blocks" , {
574586 configurable : false ,
575587 get : util . deprecate ( function ( ) {
576- return this . _blocks . getFrozenArray ( ) ;
588+ return this . _blocks . getCachedInfo ( getFrozenArray ) ;
577589 } , "Chunk.blocks: Use Chunk.getBlocks() instead" ) ,
578590 set : util . deprecate ( function ( value ) {
579591 this . setBlocks ( value ) ;
0 commit comments