mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
optimization: do not instantiate weak/soft refs when not needed
GitOrigin-RevId: 93095b63af562f76d4ebc1108daea5ead860096a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e6dbd42817
commit
1f983b8625
@@ -351,22 +351,21 @@ abstract class ConcurrentRefHashMap<K, V> extends AbstractMap<K, V> implements C
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean remove(@NotNull Object key, @NotNull Object value) {
|
public boolean remove(@NotNull Object key, @NotNull Object value) {
|
||||||
//noinspection unchecked
|
boolean removed = myMap.remove(createHardKey(key), value);
|
||||||
boolean removed = myMap.remove(createKeyReference((K)key), value);
|
|
||||||
processQueue();
|
processQueue();
|
||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean replace(@NotNull K key, @NotNull V oldValue, @NotNull V newValue) {
|
public boolean replace(@NotNull K key, @NotNull V oldValue, @NotNull V newValue) {
|
||||||
boolean replaced = myMap.replace(createKeyReference(key), oldValue, newValue);
|
boolean replaced = myMap.replace(createHardKey(key), oldValue, newValue);
|
||||||
processQueue();
|
processQueue();
|
||||||
return replaced;
|
return replaced;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public V replace(@NotNull K key, @NotNull V value) {
|
public V replace(@NotNull K key, @NotNull V value) {
|
||||||
V replaced = myMap.replace(createKeyReference(key), value);
|
V replaced = myMap.replace(createHardKey(key), value);
|
||||||
processQueue();
|
processQueue();
|
||||||
return replaced;
|
return replaced;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import java.lang.ref.SoftReference;
|
|||||||
* Concurrent map with soft keys and soft values.
|
* Concurrent map with soft keys and soft values.
|
||||||
* Null keys are NOT allowed
|
* Null keys are NOT allowed
|
||||||
* Null values are NOT allowed
|
* Null values are NOT allowed
|
||||||
* To instantiate use {@link ContainerUtil#createConcurrentWeakKeySoftValueMap(int, float, int, HashingStrategy)}
|
* To instantiate use {@link ContainerUtil#createConcurrentSoftKeySoftValueMap()}
|
||||||
*/
|
*/
|
||||||
final class ConcurrentSoftKeySoftValueHashMap<K, V> extends ConcurrentWeakKeySoftValueHashMap<K,V> {
|
final class ConcurrentSoftKeySoftValueHashMap<K, V> extends ConcurrentWeakKeySoftValueHashMap<K,V> {
|
||||||
ConcurrentSoftKeySoftValueHashMap(int initialCapacity,
|
ConcurrentSoftKeySoftValueHashMap(int initialCapacity,
|
||||||
|
|||||||
@@ -341,10 +341,9 @@ public class ConcurrentWeakKeySoftValueHashMap<K, V> implements ConcurrentMap<K,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean replace(@NotNull K key, @NotNull V oldValue, @NotNull V newValue) {
|
public boolean replace(@NotNull K key, @NotNull V oldValue, @NotNull V newValue) {
|
||||||
KeyReference<K, V> oldKeyReference = createKeyReference(key, oldValue);
|
KeyReference<K, V> oldKeyReference = createHardKey(key);
|
||||||
ValueReference<K, V> oldValueReference = oldKeyReference.getValueReference();
|
ValueReference<K, V> oldValueReference = createValueReference(oldValue, myValueQueue);
|
||||||
KeyReference<K, V> newKeyReference = createKeyReference(key, newValue);
|
ValueReference<K, V> newValueReference = createValueReference(newValue, myValueQueue);
|
||||||
ValueReference<K, V> newValueReference = newKeyReference.getValueReference();
|
|
||||||
|
|
||||||
boolean replaced = myMap.replace(oldKeyReference, oldValueReference, newValueReference);
|
boolean replaced = myMap.replace(oldKeyReference, oldValueReference, newValueReference);
|
||||||
processQueues();
|
processQueues();
|
||||||
@@ -353,8 +352,8 @@ public class ConcurrentWeakKeySoftValueHashMap<K, V> implements ConcurrentMap<K,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public V replace(@NotNull K key, @NotNull V value) {
|
public V replace(@NotNull K key, @NotNull V value) {
|
||||||
KeyReference<K, V> keyReference = createKeyReference(key, value);
|
KeyReference<K, V> keyReference = createHardKey(key);
|
||||||
ValueReference<K, V> valueReference = keyReference.getValueReference();
|
ValueReference<K, V> valueReference = createValueReference(value, myValueQueue);
|
||||||
ValueReference<K, V> result = myMap.replace(keyReference, valueReference);
|
ValueReference<K, V> result = myMap.replace(keyReference, valueReference);
|
||||||
V prev = result == null ? null : result.get();
|
V prev = result == null ? null : result.get();
|
||||||
processQueues();
|
processQueues();
|
||||||
|
|||||||
Reference in New Issue
Block a user