mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[performance] A lot of memory allocated from InspectionVisitorOptimizer.getTargetPsiClasses for lambdas
GitOrigin-RevId: a7f330d3fd1633ee1d17040ba114a0daf4a42eb1
This commit is contained in:
committed by
intellij-monorepo-bot
parent
38d7e8c489
commit
9765a5c4ce
+10
-7
@@ -35,6 +35,7 @@ import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Infers classes of elements for inspection visitors to skip some of the PSI elements during inspection pass.
|
||||
@@ -80,6 +81,14 @@ public final class InspectionVisitorOptimizer {
|
||||
return acceptingPsiTypes;
|
||||
}
|
||||
|
||||
private static final Function<Class<?>, Collection<Class<?>>> TARGET_PSI_CLASSES_INIT = aSuper -> {
|
||||
List<Class<?>> c = new ArrayList<>(10);
|
||||
if (!aSuper.isInterface() && !Modifier.isAbstract(aSuper.getModifiers())) { // PSI elements in the tree cannot be abstract
|
||||
c.add(aSuper);
|
||||
}
|
||||
return c;
|
||||
};
|
||||
|
||||
private static @NotNull Map<Class<?>, Collection<Class<?>>> getTargetPsiClasses(@NotNull List<? extends PsiElement> elements) {
|
||||
if (!useOptimizedVisitors) return Collections.emptyMap();
|
||||
|
||||
@@ -92,13 +101,7 @@ public final class InspectionVisitorOptimizer {
|
||||
// this check guarantees that items are unique in value collections, so we can use simple lists inside
|
||||
if (uniqueElementClasses.add(elementClass)) {
|
||||
for (Class<?> aSuper : SELF_AND_SUPERS.get(elementClass)) {
|
||||
Collection<Class<?>> classes = targetPsiClasses.computeIfAbsent(aSuper, aClass -> {
|
||||
List<Class<?>> c = new ArrayList<>(10);
|
||||
if (!aSuper.isInterface() && !Modifier.isAbstract(aSuper.getModifiers())) { // PSI elements in the tree cannot be abstract
|
||||
c.add(aSuper);
|
||||
}
|
||||
return c;
|
||||
});
|
||||
Collection<Class<?>> classes = targetPsiClasses.computeIfAbsent(aSuper, TARGET_PSI_CLASSES_INIT);
|
||||
classes.add(elementClass);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user