cache effective reference search scopes

This commit is contained in:
peter
2016-08-24 17:53:02 +02:00
parent 8d3da1a5c2
commit fa2142d2ea
2 changed files with 14 additions and 4 deletions
@@ -38,6 +38,7 @@ public class MethodReferencesSearch extends ExtensibleQueryFactory<PsiReference,
private final PsiMethod myMethod;
private final Project myProject;
private final SearchScope myScope;
private volatile SearchScope myEffectiveScope;
private final boolean myStrictSignatureSearch;
private final SearchRequestCollector myOptimizer;
private final boolean isSharedOptimizer;
@@ -93,8 +94,11 @@ public class MethodReferencesSearch extends ExtensibleQueryFactory<PsiReference,
@NotNull
public SearchScope getEffectiveSearchScope () {
SearchScope accessScope = PsiSearchHelper.SERVICE.getInstance(myMethod.getProject()).getUseScope(myMethod);
return myScope.intersectWith(accessScope);
SearchScope scope = myEffectiveScope;
if (scope == null) {
myEffectiveScope = scope = myScope.intersectWith(PsiSearchHelper.SERVICE.getInstance(myMethod.getProject()).getUseScope(myMethod));
}
return scope;
}
}
@@ -43,6 +43,7 @@ public class ReferencesSearch extends ExtensibleQueryFactory<PsiReference, Refer
public static class SearchParameters implements DumbAwareSearchParameters {
private final PsiElement myElementToSearch;
private final SearchScope myScope;
private volatile SearchScope myEffectiveScope;
private final boolean myIgnoreAccessScope;
private final SearchRequestCollector myOptimizer;
private final Project myProject;
@@ -104,8 +105,13 @@ public class ReferencesSearch extends ExtensibleQueryFactory<PsiReference, Refer
if (myIgnoreAccessScope) {
return myScope;
}
SearchScope accessScope = PsiSearchHelper.SERVICE.getInstance(myElementToSearch.getProject()).getUseScope(myElementToSearch);
return myScope.intersectWith(accessScope);
SearchScope scope = myEffectiveScope;
if (scope == null) {
SearchScope useScope = PsiSearchHelper.SERVICE.getInstance(myElementToSearch.getProject()).getUseScope(myElementToSearch);
myEffectiveScope = scope = myScope.intersectWith(useScope);
}
return scope;
}
}