From 7599f910fb5bfab87ddb05ebb7826a40c2a10a69 Mon Sep 17 00:00:00 2001 From: Anton Tarasov Date: Wed, 9 Dec 2015 12:28:13 +0300 Subject: [PATCH] IDEA-148739 [follow-up] Enable gutter icons scaling by default Set a limit to the cache of icons of different sizes. When a gutter icon is scaled up/down as one is zooming, it can take about 50 values. There's no need to keep all those sizes in the cache. Moreover, the cache is rather used for a "common case", when an icon is scaled to meet different modes, like "standard", "presentation" w/ combination of possible "scaled" state. So, "5" should be enough for the cache limit. --- .../util/src/com/intellij/openapi/util/IconLoader.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/platform/util/src/com/intellij/openapi/util/IconLoader.java b/platform/util/src/com/intellij/openapi/util/IconLoader.java index 1bb7082fd170..3803beffe625 100644 --- a/platform/util/src/com/intellij/openapi/util/IconLoader.java +++ b/platform/util/src/com/intellij/openapi/util/IconLoader.java @@ -42,6 +42,7 @@ import java.lang.ref.Reference; import java.lang.reflect.Field; import java.net.URL; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentMap; @@ -361,6 +362,7 @@ public final class IconLoader { private float scale; private ImageFilter filter; private HashMap scaledIcons; + private static final int SCALED_ICONS_CACHE_LIMIT = 5; public CachedImageIcon(@NotNull URL url) { myUrl = url; @@ -430,7 +432,12 @@ public final class IconLoader { return this; } if (scaledIcons == null) { - scaledIcons = new HashMap(1); + scaledIcons = new LinkedHashMap(1) { + @Override + public boolean removeEldestEntry(Map.Entry entry) { + return size() > SCALED_ICONS_CACHE_LIMIT; + } + }; } // TODO: consider clearing the cache on SCALE change