mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
optimization: do not reallocate/repeatedly find order root type in the hot path (part of KTIJ-27513 K2 IDE: Slow reference search for specific symbols in unused symbol inspection)
GitOrigin-RevId: 0931017e36cc1178070f795e64d1473f244081cc
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d645b3e6e4
commit
dde921139f
@@ -730,7 +730,7 @@ public class ExternalAnnotationsManagerImpl extends ModCommandAwareExternalAnnot
|
||||
if (!entries.isEmpty()) {
|
||||
for (OrderEntry entry : entries) {
|
||||
if (!(entry instanceof ModuleOrderEntry)) {
|
||||
if (!AnnotationOrderRootType.getUrls(entry).isEmpty()) {
|
||||
if (AnnotationOrderRootType.hasUrls(entry)) {
|
||||
return AnnotationPlace.EXTERNAL;
|
||||
}
|
||||
break;
|
||||
@@ -899,7 +899,7 @@ public class ExternalAnnotationsManagerImpl extends ModCommandAwareExternalAnnot
|
||||
if (hasAnyAnnotationsRoots()) {
|
||||
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myPsiManager.getProject()).getFileIndex();
|
||||
for (OrderEntry entry : fileIndex.getOrderEntriesForFile(file)) {
|
||||
if (!(entry instanceof ModuleOrderEntry) && !AnnotationOrderRootType.getUrls(entry).isEmpty()) {
|
||||
if (!(entry instanceof ModuleOrderEntry) && AnnotationOrderRootType.hasUrls(entry)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,7 +299,6 @@ c:com.intellij.openapi.roots.AnnotationOrderRootType
|
||||
- sf:ANNOTATIONS_ID:java.lang.String
|
||||
- s:getFiles(com.intellij.openapi.roots.OrderEntry):com.intellij.openapi.vfs.VirtualFile[]
|
||||
- s:getInstance():com.intellij.openapi.roots.OrderRootType
|
||||
- s:getUrls(com.intellij.openapi.roots.OrderEntry):java.util.List
|
||||
- skipWriteIfEmpty():Z
|
||||
c:com.intellij.openapi.roots.JavaSyntheticLibrary
|
||||
- com.intellij.openapi.roots.SyntheticLibrary
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.openapi.roots;
|
||||
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class AnnotationOrderRootType extends PersistentOrderRootType {
|
||||
public static final String ANNOTATIONS_ID = "ANNOTATIONS";
|
||||
@@ -32,44 +27,44 @@ public class AnnotationOrderRootType extends PersistentOrderRootType {
|
||||
}
|
||||
|
||||
public static VirtualFile @NotNull [] getFiles(@NotNull OrderEntry entry) {
|
||||
List<VirtualFile> result = new ArrayList<>();
|
||||
if (entry instanceof LibraryOrderEntry orderEntry) {
|
||||
Collections.addAll(result, orderEntry.getRootFiles(getInstance()));
|
||||
return orderEntry.getRootFiles(getInstance());
|
||||
}
|
||||
else if (entry instanceof JdkOrderEntry orderEntry) {
|
||||
Collections.addAll(result, orderEntry.getRootFiles(getInstance()));
|
||||
return orderEntry.getRootFiles(getInstance());
|
||||
}
|
||||
else if (entry instanceof ModuleSourceOrderEntry orderEntry) {
|
||||
JavaModuleExternalPaths moduleExtension = orderEntry.getRootModel().getModuleExtension(JavaModuleExternalPaths.class);
|
||||
if (moduleExtension != null) {
|
||||
Collections.addAll(result, moduleExtension.getExternalAnnotationsRoots());
|
||||
return moduleExtension.getExternalAnnotationsRoots();
|
||||
}
|
||||
else {
|
||||
return VirtualFile.EMPTY_ARRAY;
|
||||
}
|
||||
}
|
||||
return VfsUtilCore.toVirtualFileArray(result);
|
||||
return VirtualFile.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
public static @NotNull List<String> getUrls(@NotNull OrderEntry entry) {
|
||||
List<String> result = new ArrayList<>();
|
||||
RootPolicy<List<String>> policy = new RootPolicy<>() {
|
||||
@Override
|
||||
public List<String> visitLibraryOrderEntry(@NotNull final LibraryOrderEntry orderEntry, final List<String> value) {
|
||||
Collections.addAll(value, orderEntry.getRootUrls(getInstance()));
|
||||
return value;
|
||||
}
|
||||
private final static RootPolicy<String[]> GET_ANNOTATION_URL_POLICY = new RootPolicy<>() {
|
||||
@Override
|
||||
public String[] visitLibraryOrderEntry(@NotNull LibraryOrderEntry libraryOrderEntry, String[] value) {
|
||||
return libraryOrderEntry.getRootUrls(getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> visitJdkOrderEntry(@NotNull final JdkOrderEntry orderEntry, final List<String> value) {
|
||||
Collections.addAll(value, orderEntry.getRootUrls(getInstance()));
|
||||
return value;
|
||||
}
|
||||
@Override
|
||||
public String[] visitJdkOrderEntry(@NotNull JdkOrderEntry jdkOrderEntry, String[] value) {
|
||||
return jdkOrderEntry.getRootUrls(getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> visitModuleSourceOrderEntry(@NotNull ModuleSourceOrderEntry orderEntry, List<String> value) {
|
||||
Collections.addAll(value, orderEntry.getRootModel().getModuleExtension(JavaModuleExternalPaths.class).getExternalAnnotationsUrls());
|
||||
return value;
|
||||
}
|
||||
};
|
||||
entry.accept(policy, result);
|
||||
return result;
|
||||
@Override
|
||||
public String[] visitModuleSourceOrderEntry(@NotNull ModuleSourceOrderEntry moduleSourceOrderEntry, String[] value) {
|
||||
return moduleSourceOrderEntry.getRootModel().getModuleExtension(JavaModuleExternalPaths.class).getExternalAnnotationsUrls();
|
||||
}
|
||||
};
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static boolean hasUrls(@NotNull OrderEntry entry) {
|
||||
String[] urls = entry.accept(GET_ANNOTATION_URL_POLICY, null);
|
||||
return urls != null && urls.length != 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.openapi.roots;
|
||||
|
||||
import com.intellij.util.ArrayUtilRt;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class JavadocOrderRootType extends PersistentOrderRootType {
|
||||
@ApiStatus.Internal
|
||||
@@ -21,32 +16,23 @@ public class JavadocOrderRootType extends PersistentOrderRootType {
|
||||
return getOrderRootType(JavadocOrderRootType.class);
|
||||
}
|
||||
|
||||
private final static RootPolicy<String @NotNull []> GET_JAVADOC_URL_POLICY = new RootPolicy<>() {
|
||||
@Override
|
||||
public String @NotNull [] visitLibraryOrderEntry(@NotNull LibraryOrderEntry libraryOrderEntry, String[] value) {
|
||||
return libraryOrderEntry.getRootUrls(getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String @NotNull [] visitJdkOrderEntry(@NotNull JdkOrderEntry jdkOrderEntry, String[] value) {
|
||||
return jdkOrderEntry.getRootUrls(getInstance());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String @NotNull [] visitModuleSourceOrderEntry(@NotNull ModuleSourceOrderEntry moduleSourceOrderEntry, String[] value) {
|
||||
return moduleSourceOrderEntry.getRootModel().getModuleExtension(JavaModuleExternalPaths.class).getJavadocUrls();
|
||||
}
|
||||
};
|
||||
public static String @NotNull [] getUrls(@NotNull OrderEntry entry) {
|
||||
return ((JavadocOrderRootType)getInstance()).doGetUrls(entry);
|
||||
}
|
||||
|
||||
private String @NotNull [] doGetUrls(@NotNull OrderEntry entry) {
|
||||
List<String> result = new ArrayList<>();
|
||||
RootPolicy<List<String>> policy = new RootPolicy<>() {
|
||||
@Override
|
||||
public List<String> visitLibraryOrderEntry(@NotNull final LibraryOrderEntry orderEntry, final List<String> value) {
|
||||
Collections.addAll(value, orderEntry.getRootUrls(JavadocOrderRootType.this));
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> visitJdkOrderEntry(@NotNull final JdkOrderEntry orderEntry, final List<String> value) {
|
||||
Collections.addAll(value, orderEntry.getRootUrls(JavadocOrderRootType.this));
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> visitModuleSourceOrderEntry(@NotNull final ModuleSourceOrderEntry orderEntry, final List<String> value) {
|
||||
Collections.addAll(value, orderEntry.getRootModel().getModuleExtension(JavaModuleExternalPaths.class).getJavadocUrls());
|
||||
return value;
|
||||
}
|
||||
};
|
||||
entry.accept(policy, result);
|
||||
return ArrayUtilRt.toStringArray(result);
|
||||
return entry.accept(GET_JAVADOC_URL_POLICY, null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user