mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
performance: make isEmpty() allocate-free, tests added
This commit is contained in:
@@ -97,17 +97,20 @@ public class ConcurrentMapsTest {
|
||||
}
|
||||
|
||||
private void checkKeyIsTossedAfterGCPressure(Map<Object, Object> map) {
|
||||
assertTrue(map.isEmpty());
|
||||
map.put(new Object(), new Object());
|
||||
|
||||
//noinspection SizeReplaceableByIsEmpty
|
||||
do {
|
||||
map.put(this, this); // to run processQueues();
|
||||
assertFalse(map.isEmpty());
|
||||
map.remove(this);
|
||||
|
||||
GCUtil.tryGcSoftlyReachableObjects();
|
||||
System.gc();
|
||||
}
|
||||
while (map.size() != 0);
|
||||
assertTrue(map.isEmpty());
|
||||
assertEquals(0, map.size());
|
||||
map.put(this, this);
|
||||
assertEquals(1, map.size());
|
||||
@@ -255,6 +258,7 @@ public class ConcurrentMapsTest {
|
||||
}
|
||||
|
||||
private static void checkTossedKeyAndValue(@NotNull RefKeyRefValueHashMap<Object, Object> map) {
|
||||
assertTrue(map.isEmpty());
|
||||
map.put(new Object(), new Object());
|
||||
|
||||
do {
|
||||
|
||||
@@ -126,7 +126,8 @@ abstract class ConcurrentRefHashMap<K, V> extends AbstractMap<K, V> implements C
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return myMap.isEmpty();
|
||||
// make easier and alloc-free call to myMap first
|
||||
return myMap.isEmpty() || entrySet().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -202,7 +202,8 @@ abstract class RefHashMap<K, V> extends AbstractMap<K, V> implements Map<K, V> {
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return myMap.isEmpty();
|
||||
// make easier and alloc-free call to myMap first
|
||||
return myMap.isEmpty() || entrySet().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -383,7 +384,8 @@ abstract class RefHashMap<K, V> extends AbstractMap<K, V> implements Map<K, V> {
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<Entry<K, V>> entrySet() {
|
||||
if (entrySet == null) entrySet = new EntrySet();
|
||||
return entrySet;
|
||||
Set<Entry<K, V>> es = entrySet;
|
||||
if (es == null) entrySet = es = new EntrySet();
|
||||
return es;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user