File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,14 +26,17 @@ function normalizeColor(color) {
2626 return null ;
2727 }
2828
29- const cachedColor = cachedColors . get ( color ) ;
30- if ( cachedColor !== undefined ) {
29+ if ( cachedColors . has ( color ) ) {
30+ // Map iteration order follows insertion order, so re-inserting on every
31+ // hit keeps the least-recently-used entry first.
32+ const cachedColor = cachedColors . get ( color ) ;
33+ cachedColors . delete ( color ) ;
34+ cachedColors . set ( color , cachedColor ) ;
3135 return cachedColor ;
3236 }
3337 const normalizedColor = parseColorString ( color ) ;
34- // To avoid CachedColors increasing indefinetly
3538 if ( cachedColors . size >= 1024 ) {
36- cachedColors . clear ( ) ;
39+ cachedColors . delete ( cachedColors . keys ( ) . next ( ) . value ) ;
3740 }
3841 cachedColors . set ( color , normalizedColor ) ;
3942 return normalizedColor ;
You can’t perform that action at this time.
0 commit comments