Skip to content

Commit 2d370d4

Browse files
committed
Memory and performance optimization. Don't create empty instance every time, reuse the same one instead. It is an immutable data structure after all ;-)
1 parent 2b62f01 commit 2d370d4

File tree

1 file changed

+2
-1
lines changed
  • src/main/java/com/romix/scala/collection/concurrent

1 file changed

+2
-1
lines changed

src/main/java/com/romix/scala/collection/concurrent/TrieMap.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class TrieMap<K, V> extends AbstractMap<K, V> implements ConcurrentMap<K,
3434
private static final AtomicReferenceFieldUpdater<TrieMap, Object> ROOT_UPDATER = AtomicReferenceFieldUpdater.newUpdater(TrieMap.class, Object.class, "root");
3535
private static final long serialVersionUID = 1L;
3636
private static final Field READONLY_FIELD;
37+
private static final TrieMap EMPTY = new TrieMap();
3738

3839
static {
3940
final Field f;
@@ -54,7 +55,7 @@ public class TrieMap<K, V> extends AbstractMap<K, V> implements ConcurrentMap<K,
5455
private transient final EntrySet entrySet = new EntrySet ();
5556

5657
public static <K,V> TrieMap<K,V> empty () {
57-
return new TrieMap<K,V> ();
58+
return EMPTY;
5859
}
5960

6061
// static class MangledHashing<K> extends Hashing<K> {

0 commit comments

Comments
 (0)