From be83ec87f305c83c08ced3ee3cc24611f9ae218f Mon Sep 17 00:00:00 2001 From: Maxmtg Date: Tue, 19 Mar 2013 19:25:16 +0000 Subject: [PATCH] a smarter way to make ImageLoader check for an image only once. It uses a placeholder value, that is not null and therefore may be added into cache without errors --- src/main/java/forge/ImageCache.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/forge/ImageCache.java b/src/main/java/forge/ImageCache.java index 31631a3804b..26101b3e824 100644 --- a/src/main/java/forge/ImageCache.java +++ b/src/main/java/forge/ImageCache.java @@ -68,7 +68,7 @@ public class ImageCache { public static final String TOURNAMENTPACK_PREFIX = "o:"; static private final LoadingCache CACHE = CacheBuilder.newBuilder().softValues().build(new ImageLoader()); - + private static final BufferedImage defaultImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); /** * retrieve an image from the cache. returns null if the image is not found in the cache * and cannot be loaded from disk. pass -1 for width and/or height to avoid resizing in that dimension. @@ -120,8 +120,13 @@ public class ImageCache { boolean mayEnlarge = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_SCALE_LARGER); BufferedImage original = getImage(key); + + if (original == defaultImage) { // the found image is a placeholder for missing picture? + return null; + } + if (null == original) { - // CACHE.put(key, null); // This instructs cache to give up finding a picture if it was not found once + CACHE.put(key, defaultImage); // This instructs cache to give up finding a picture if it was not found once return null; }