mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
wise cache in UserDataCache&FieldCache
This commit is contained in:
@@ -21,6 +21,7 @@ import com.intellij.util.concurrency.JBReentrantReadWriteLock;
|
||||
import com.intellij.util.concurrency.LockFactory;
|
||||
|
||||
public abstract class FieldCache<T, Owner,AccessorParameter,Parameter> {
|
||||
private static final RecursionGuard ourGuard = RecursionManager.createGuard("fieldCache");
|
||||
private final JBLock r;
|
||||
private final JBLock w;
|
||||
|
||||
@@ -46,8 +47,11 @@ public abstract class FieldCache<T, Owner,AccessorParameter,Parameter> {
|
||||
try {
|
||||
result = getValue(owner, a);
|
||||
if (result == null) {
|
||||
RecursionGuard.StackStamp stamp = ourGuard.markStack();
|
||||
result = compute(owner, p);
|
||||
putValue(result, owner, a);
|
||||
if (stamp.mayCacheNow()) {
|
||||
putValue(result, owner, a);
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.intellij.openapi.util;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
public abstract class UserDataCache<T, Owner extends UserDataHolder, Param> extends FieldCache<T, Owner, Key<T>, Param> {
|
||||
private static final RecursionGuard ourGuard = RecursionManager.createGuard("userDataCache");
|
||||
private final Key<T> myKey;
|
||||
|
||||
protected UserDataCache() {
|
||||
@@ -49,8 +50,11 @@ public abstract class UserDataCache<T, Owner extends UserDataHolder, Param> exte
|
||||
public T get(Key<T> a, Owner owner, Param p) {
|
||||
T value = owner.getUserData(a);
|
||||
if (value == null) {
|
||||
RecursionGuard.StackStamp stamp = ourGuard.markStack();
|
||||
value = compute(owner, p);
|
||||
value = ((UserDataHolderEx)owner).putUserDataIfAbsent(a, value);
|
||||
if (stamp.mayCacheNow()) {
|
||||
value = ((UserDataHolderEx)owner).putUserDataIfAbsent(a, value);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user