Ver código fonte

Work around hash collision #fml

Vishnu Mohandas 4 anos atrás
pai
commit
f7f038033b
1 arquivos alterados com 8 adições e 21 exclusões
  1. 8 21
      lib/core/cache/thumbnail_cache.dart

+ 8 - 21
lib/core/cache/thumbnail_cache.dart

@@ -5,10 +5,12 @@ import 'package:photos/core/constants.dart';
 import 'package:photos/models/file.dart';
 
 class ThumbnailLruCache {
-  static LRUMap<_ThumbnailCacheKey, Uint8List> _map = LRUMap(1000);
+  static LRUMap<String, Uint8List> _map = LRUMap(1000);
 
   static Uint8List get(File photo, [int size]) {
-    return _map.get(_ThumbnailCacheKey(photo, size ?? THUMBNAIL_LARGE_SIZE));
+    return _map.get(photo.generatedID.toString() +
+        "_" +
+        (size != null ? size.toString() : THUMBNAIL_LARGE_SIZE.toString()));
   }
 
   static void put(
@@ -17,24 +19,9 @@ class ThumbnailLruCache {
     int size,
   ]) {
     _map.put(
-        _ThumbnailCacheKey(photo, size ?? THUMBNAIL_LARGE_SIZE), imageData);
+        photo.generatedID.toString() +
+            "_" +
+            (size != null ? size.toString() : THUMBNAIL_LARGE_SIZE.toString()),
+        imageData);
   }
 }
-
-class _ThumbnailCacheKey {
-  File photo;
-  int size;
-
-  _ThumbnailCacheKey(this.photo, this.size);
-
-  @override
-  bool operator ==(Object other) =>
-      identical(this, other) ||
-      other is _ThumbnailCacheKey &&
-          runtimeType == other.runtimeType &&
-          photo.hashCode == other.photo.hashCode &&
-          size == other.size;
-
-  @override
-  int get hashCode => photo.hashCode * size.hashCode;
-}