@@ -21,6 +21,27 @@ const sortByIdentifier = (a, b) => {
2121 return 0 ;
2222} ;
2323
24+ const getFrozenArray = set => Object . freeze ( Array . from ( set ) ) ;
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 ) {
@@ -70,7 +91,7 @@ class Chunk {
7091 * @return {Array } - an array containing the chunks
7192 */
7293 getChunks ( ) {
73- return Array . from ( this . _chunks ) ;
94+ return this . _chunks . getFromCache ( getArray ) ;
7495 }
7596
7697 getNumberOfChunks ( ) {
@@ -85,7 +106,7 @@ class Chunk {
85106 * @return {Array } - an array containing the parents
86107 */
87108 getParents ( ) {
88- return Array . from ( this . _parents ) ;
109+ return this . _parents . getFromCache ( getArray ) ;
89110 }
90111
91112 setParents ( newParents ) {
@@ -114,7 +135,7 @@ class Chunk {
114135 * @return {Array } - an array containing the blocks
115136 */
116137 getBlocks ( ) {
117- return Array . from ( this . _blocks ) ;
138+ return this . _blocks . getFromCache ( getArray ) ;
118139 }
119140
120141 setBlocks ( newBlocks ) {
@@ -274,16 +295,11 @@ class Chunk {
274295 }
275296
276297 getModules ( ) {
277- return Array . from ( this . _modules ) ;
298+ return this . _modules . getFromCache ( getArray ) ;
278299 }
279300
280301 getModulesIdent ( ) {
281- this . _modules . sort ( ) ;
282- let str = "" ;
283- this . _modules . forEach ( m => {
284- str += m . identifier ( ) + "#" ;
285- } ) ;
286- return str ;
302+ return this . _modules . getFromUnorderedCache ( getModulesIdent ) ;
287303 }
288304
289305 remove ( reason ) {
@@ -457,11 +473,7 @@ class Chunk {
457473 }
458474
459475 modulesSize ( ) {
460- let count = 0 ;
461- for ( const module of this . _modules ) {
462- count += module . size ( ) ;
463- }
464- return count ;
476+ return this . _modules . getFromUnorderedCache ( getModulesSize ) ;
465477 }
466478
467479 size ( options ) {
@@ -548,7 +560,7 @@ class Chunk {
548560Object . defineProperty ( Chunk . prototype , "modules" , {
549561 configurable : false ,
550562 get : util . deprecate ( function ( ) {
551- return this . _modules . getFrozenArray ( ) ;
563+ return this . _modules . getFromCache ( getFrozenArray ) ;
552564 } , "Chunk.modules is deprecated. Use Chunk.getNumberOfModules/mapModules/forEachModule/containsModule instead." ) ,
553565 set : util . deprecate ( function ( value ) {
554566 this . setModules ( value ) ;
@@ -558,7 +570,7 @@ Object.defineProperty(Chunk.prototype, "modules", {
558570Object . defineProperty ( Chunk . prototype , "chunks" , {
559571 configurable : false ,
560572 get : util . deprecate ( function ( ) {
561- return this . _chunks . getFrozenArray ( ) ;
573+ return this . _chunks . getFromCache ( getFrozenArray ) ;
562574 } , "Chunk.chunks: Use Chunk.getChunks() instead" ) ,
563575 set ( ) {
564576 throw new Error ( "Readonly. Use Chunk.addChunk/removeChunk/getChunks to access/modify chunks." ) ;
@@ -568,7 +580,7 @@ Object.defineProperty(Chunk.prototype, "chunks", {
568580Object . defineProperty ( Chunk . prototype , "parents" , {
569581 configurable : false ,
570582 get : util . deprecate ( function ( ) {
571- return this . _parents . getFrozenArray ( ) ;
583+ return this . _parents . getFromCache ( getFrozenArray ) ;
572584 } , "Chunk.parents: Use Chunk.getParents() instead" ) ,
573585 set : util . deprecate ( function ( value ) {
574586 this . setParents ( value ) ;
@@ -578,7 +590,7 @@ Object.defineProperty(Chunk.prototype, "parents", {
578590Object . defineProperty ( Chunk . prototype , "blocks" , {
579591 configurable : false ,
580592 get : util . deprecate ( function ( ) {
581- return this . _blocks . getFrozenArray ( ) ;
593+ return this . _blocks . getFromCache ( getFrozenArray ) ;
582594 } , "Chunk.blocks: Use Chunk.getBlocks() instead" ) ,
583595 set : util . deprecate ( function ( value ) {
584596 this . setBlocks ( value ) ;
0 commit comments