mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-25 16:29:28 +00:00
avoid unnecessary locking in ConcurrentReferenceHashMap's implementation of computeIfAbsent and computeIfPresent
Signed-off-by: Christian Schuster <christian@dnup.de>
This commit is contained in:
committed by
Juergen Hoeller
parent
98d4046e4b
commit
a9b1d6335e
@@ -371,6 +371,12 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
|
||||
|
||||
@Override
|
||||
public @Nullable V computeIfAbsent(@Nullable K key, Function<@Nullable ? super K, @Nullable ? extends V> mappingFunction) {
|
||||
// avoid locking if entry is present
|
||||
Reference<K, V> ref = getReference(key, Restructure.NEVER);
|
||||
Entry<K, V> entry = (ref != null ? ref.get() : null);
|
||||
if (entry != null) {
|
||||
return entry.getValue();
|
||||
}
|
||||
return doTask(key, new Task<V>(TaskOption.RESTRUCTURE_BEFORE, TaskOption.RESIZE) {
|
||||
@Override
|
||||
protected @Nullable V execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> entry, @Nullable Entries<V> entries) {
|
||||
@@ -390,6 +396,12 @@ public class ConcurrentReferenceHashMap<K, V> extends AbstractMap<K, V> implemen
|
||||
|
||||
@Override
|
||||
public @Nullable V computeIfPresent(@Nullable K key, BiFunction<@Nullable ? super K, @Nullable ? super V, @Nullable ? extends V> remappingFunction) {
|
||||
// avoid locking if entry is absent
|
||||
Reference<K, V> ref = getReference(key, Restructure.NEVER);
|
||||
Entry<K, V> entry = (ref != null ? ref.get() : null);
|
||||
if (entry == null) {
|
||||
return null;
|
||||
}
|
||||
return doTask(key, new Task<V>(TaskOption.RESTRUCTURE_BEFORE, TaskOption.RESIZE) {
|
||||
@Override
|
||||
protected @Nullable V execute(@Nullable Reference<K, V> ref, @Nullable Entry<K, V> entry, @Nullable Entries<V> entries) {
|
||||
|
||||
Reference in New Issue
Block a user