From c9704493fec4714e6ebd7173b5241ed62a072a81 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 25 Jan 2012 14:51:09 +0400 Subject: [PATCH] performance --- .../psi/impl/source/SourceTreeToPsiMap.java | 3 +- .../daemon/impl/LocalInspectionsPass.java | 39 ++++++++++--------- .../progress/util/ProgressWrapper.java | 4 +- .../util/containers/ContainerUtil.java | 11 ++++++ 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/platform/core-impl/src/com/intellij/psi/impl/source/SourceTreeToPsiMap.java b/platform/core-impl/src/com/intellij/psi/impl/source/SourceTreeToPsiMap.java index 01054a656a17..9ebb20533225 100644 --- a/platform/core-impl/src/com/intellij/psi/impl/source/SourceTreeToPsiMap.java +++ b/platform/core-impl/src/com/intellij/psi/impl/source/SourceTreeToPsiMap.java @@ -27,8 +27,7 @@ public class SourceTreeToPsiMap { @Nullable public static PsiElement treeElementToPsi(@Nullable final ASTNode element) { - if (element == null) return null; - return element.getPsi(); + return element == null ? null : element.getPsi(); } @NotNull diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java index fd2e12e5f23a..1339a2c9fc76 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/LocalInspectionsPass.java @@ -233,27 +233,31 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass private static MultiMap getToolsForElements(List toolWrappers, boolean checkDumbAwareness, List inside, List outside) { - Set languages = new HashSet(); + Set languages = new THashSet(); + Map langIds = new THashMap(); + Set dialects = new THashSet(); for (PsiElement element : inside) { - languages.add(element.getLanguage()); + Language language = element.getLanguage(); + if (languages.add(language)) { + langIds.put(language.getID(), language); + for (Language dialect : language.getDialects()) { + dialects.add(dialect.getID()); + } + } } for (PsiElement element : outside) { - languages.add(element.getLanguage()); - } - Map langIds = new HashMap(); - for (Language language : languages) { - langIds.put(language.getID(), language); - } - Set dialects = new HashSet(); - for (Language language : languages) { - for (Language dialect : language.getDialects()) { - dialects.add(dialect.getID()); + Language language = element.getLanguage(); + if (languages.add(language)) { + langIds.put(language.getID(), language); + for (Language dialect : language.getDialects()) { + dialects.add(dialect.getID()); + } } } MultiMap map = new MultiMap() { @Override protected Collection createCollection() { - return new HashSet(); + return new THashSet(); } @Override @@ -319,11 +323,11 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass } } }; - PsiElementVisitor visitor = createVisitorAndAcceptElements(tool, holder, isOnTheFly, session, elements, - (Set)pair.getValue()); + Set languages = (Set)pair.getValue(); + PsiElementVisitor visitor = createVisitorAndAcceptElements(tool, holder, isOnTheFly, session, elements, languages); synchronized (init) { - init.add(new InspectionContext(tool, holder, visitor, (Set)pair.getValue())); + init.add(new InspectionContext(tool, holder, visitor, languages)); } advanceProgress(1); @@ -477,7 +481,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass } }, myProject.getDisposed(), 200); - private final Set emptyActionRegistered = Collections.synchronizedSet(new HashSet()); + private final Set emptyActionRegistered = Collections.synchronizedSet(new THashSet()); private void addDescriptorIncrementally(@NotNull final ProblemDescriptor descriptor, @NotNull final LocalInspectionTool tool, @@ -777,7 +781,6 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass } private static class InspectionContext { - private InspectionContext(LocalInspectionTool tool, ProblemsHolder holder, PsiElementVisitor visitor, Set languageIds) { this.tool = tool; this.holder = holder; diff --git a/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressWrapper.java b/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressWrapper.java index 0b37d4b23b84..296443cb6e47 100644 --- a/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressWrapper.java +++ b/platform/platform-impl/src/com/intellij/openapi/progress/util/ProgressWrapper.java @@ -43,11 +43,11 @@ public class ProgressWrapper extends ProgressIndicatorBase { @Nullable public static ProgressWrapper wrap(@Nullable ProgressIndicator indicator) { - return indicator == null ? null : new ProgressWrapper(indicator); + return indicator == null || indicator instanceof ProgressWrapper ? (ProgressWrapper)indicator : new ProgressWrapper(indicator); } public static ProgressIndicator unwrap(ProgressIndicator indicator) { return indicator instanceof ProgressWrapper ? - ((ProgressWrapper)indicator).getOriginalProgressIndicator():indicator; + ((ProgressWrapper)indicator).getOriginalProgressIndicator() : indicator; } } diff --git a/platform/util/src/com/intellij/util/containers/ContainerUtil.java b/platform/util/src/com/intellij/util/containers/ContainerUtil.java index 01916d3e999c..0fe8eaa0f314 100644 --- a/platform/util/src/com/intellij/util/containers/ContainerUtil.java +++ b/platform/util/src/com/intellij/util/containers/ContainerUtil.java @@ -217,6 +217,17 @@ public class ContainerUtil { return true; } + public static boolean process(@NotNull List list, @NotNull Processor processor) { + //noinspection ForLoopReplaceableByForEach + for (int i = 0, size = list.size(); i < size; i++) { + T t = list.get(i); + if (!processor.process(t)) { + return false; + } + } + return true; + } + public static boolean process(@NotNull T[] iterable, @NotNull Processor processor) { for (final T t : iterable) { if (!processor.process(t)) {