From faac1c31563ff4389e14066e4677ee27e8ae1554 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 31 Jan 2017 18:01:16 +0100 Subject: [PATCH] When calculating import candidates, skip redundant deduplication performed by PsiShortNamesCacheImpl #KT-16071 Fixed --- .../kotlin/idea/core/KotlinIndicesHelper.kt | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinIndicesHelper.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinIndicesHelper.kt index e5414184096..9801489409b 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinIndicesHelper.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/KotlinIndicesHelper.kt @@ -17,9 +17,7 @@ package org.jetbrains.kotlin.idea.core import com.intellij.openapi.progress.ProgressManager -import com.intellij.psi.PsiFile -import com.intellij.psi.PsiMember -import com.intellij.psi.PsiModifier +import com.intellij.psi.* import com.intellij.psi.impl.CompositeShortNamesCache import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.search.PsiShortNamesCache @@ -49,7 +47,6 @@ import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.isHiddenInResolution import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.kotlin.types.asSimpleType import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList import java.lang.reflect.Field import java.lang.reflect.Modifier @@ -310,16 +307,31 @@ class KotlinIndicesHelper( } private fun getJavaCallables(name: String, shortNamesCache: PsiShortNamesCache): Sequence { filteredShortNamesCaches?.let { caches -> return getCallablesByName(name, scopeWithoutKotlin, caches) } - return shortNamesCache.getFieldsByName(name, scopeWithoutKotlin).asSequence() + - shortNamesCache.getMethodsByName(name, scopeWithoutKotlin).asSequence() + return shortNamesCache.getFieldsByNameUnfiltered(name, scopeWithoutKotlin).asSequence() + + shortNamesCache.getMethodsByNameUnfiltered(name, scopeWithoutKotlin).asSequence() } private fun getCallablesByName(name: String, scope: GlobalSearchScope, caches: List): Sequence { return caches.asSequence().flatMap { cache -> - cache.getMethodsByName(name, scope).asSequence() + cache.getFieldsByName(name, scope).asSequence() + cache.getMethodsByNameUnfiltered(name, scope) + cache.getFieldsByNameUnfiltered(name, scope).asSequence() } } + // getMethodsByName() removes duplicates from returned set of names, which can be excessively slow + // if the number of candidates is large (KT-16071) and is unnecessary because Kotlin performs its own + // duplicate filtering later + private fun PsiShortNamesCache.getMethodsByNameUnfiltered(name: String, scope: GlobalSearchScope): Sequence { + val result = arrayListOf() + processMethodsWithName(name, scope) { result.add(it) } + return result.asSequence() + } + + private fun PsiShortNamesCache.getFieldsByNameUnfiltered(name: String, scope: GlobalSearchScope): Sequence { + val result = arrayListOf() + processFieldsWithName(name, { field -> result.add(field); true }, scope, null) + return result.asSequence() + } + fun processKotlinCallablesByName( name: String, filter: (KtCallableDeclaration) -> Boolean,