mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-226566: Use caching for large images
merged from https://github.com/JetBrains/intellij-community/pull/1242 GitOrigin-RevId: 1da9624577c717f6358d96b89c8c34f8ed3c37bd
This commit is contained in:
committed by
intellij-monorepo-bot
parent
b35036baba
commit
bb22b64f58
@@ -26,6 +26,8 @@ import java.util.concurrent.ConcurrentMap;
|
||||
@ApiStatus.Internal
|
||||
public final class ImageDescriptor {
|
||||
private static final ConcurrentMap<String, Pair<Image, ImageLoader.Dimension2DDouble>> ourCache = ContainerUtil.createConcurrentSoftValueMap();
|
||||
private static final ConcurrentMap<String, Image> ourLargeImageCache = ContainerUtil.createConcurrentWeakValueMap();
|
||||
private static final ConcurrentMap<Image, ImageLoader.Dimension2DDouble> ourLargeImageDimensionMap = ContainerUtil.createConcurrentWeakMap();
|
||||
|
||||
final @NotNull String path;
|
||||
public final double scale; // initial scale factor
|
||||
@@ -62,6 +64,8 @@ public final class ImageDescriptor {
|
||||
|
||||
public static void clearCache() {
|
||||
ourCache.clear();
|
||||
ourLargeImageCache.clear();
|
||||
ourLargeImageDimensionMap.clear();
|
||||
ImageLoader.clearCache();
|
||||
}
|
||||
|
||||
@@ -94,6 +98,14 @@ public final class ImageDescriptor {
|
||||
origUsrSize.setSize(pair.second);
|
||||
return pair.first;
|
||||
}
|
||||
Image image = ourLargeImageCache.get(cacheKey);
|
||||
if (image != null) {
|
||||
ImageLoader.Dimension2DDouble dimension = ourLargeImageDimensionMap.get(image);
|
||||
if (dimension != null) {
|
||||
origUsrSize.setSize(dimension);
|
||||
return image;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
long start = StartUpMeasurer.isEnabled() || loadTimeConsumer != null ? StartUpMeasurer.getCurrentTime() : -1;
|
||||
@@ -128,8 +140,14 @@ public final class ImageDescriptor {
|
||||
finally {
|
||||
stream.close();
|
||||
}
|
||||
if (image != null && cacheKey != null && 4L * image.getWidth(null) * image.getHeight(null) <= ImageLoader.CACHED_IMAGE_MAX_SIZE) {
|
||||
ourCache.put(cacheKey, Pair.create(image, origUsrSize));
|
||||
if (image != null && cacheKey != null) {
|
||||
if (4L * image.getWidth(null) * image.getHeight(null) <= ImageLoader.CACHED_IMAGE_MAX_SIZE) {
|
||||
ourCache.put(cacheKey, Pair.create(image, origUsrSize));
|
||||
}
|
||||
else {
|
||||
ourLargeImageCache.put(cacheKey, image);
|
||||
ourLargeImageDimensionMap.put(image, origUsrSize);
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user