Optimize java scope members computation for non-existing names
Do not use memoized function if member with given name is not contained in the scope There are a lot of queries with names of non-existent functions, that leads to many effectively redundant Map nodes in MemoizedFunction and also cause additional computation that is worth to compute at once
This commit is contained in:
+14
-2
@@ -41,6 +41,7 @@ import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
|||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScopeImpl
|
import org.jetbrains.kotlin.resolve.scopes.MemberScopeImpl
|
||||||
import org.jetbrains.kotlin.storage.NotNullLazyValue
|
import org.jetbrains.kotlin.storage.NotNullLazyValue
|
||||||
|
import org.jetbrains.kotlin.storage.getValue
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.TypeUtils
|
import org.jetbrains.kotlin.types.TypeUtils
|
||||||
import org.jetbrains.kotlin.utils.Printer
|
import org.jetbrains.kotlin.utils.Printer
|
||||||
@@ -215,11 +216,19 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS
|
|||||||
return ResolvedValueParameters(descriptors, synthesizedNames)
|
return ResolvedValueParameters(descriptors, synthesizedNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor> = functions(name)
|
private val functionNamesLazy by c.storageManager.createLazyValue { computeFunctionNames(DescriptorKindFilter.FUNCTIONS, null) }
|
||||||
|
private val propertyNamesLazy by c.storageManager.createLazyValue { computePropertyNames(DescriptorKindFilter.VARIABLES, null) }
|
||||||
|
|
||||||
|
override fun getFunctionNames() = functionNamesLazy
|
||||||
|
override fun getVariableNames() = propertyNamesLazy
|
||||||
protected open fun computeFunctionNames(kindFilter: DescriptorKindFilter, nameFilter: ((Name) -> Boolean)?): Set<Name>
|
protected open fun computeFunctionNames(kindFilter: DescriptorKindFilter, nameFilter: ((Name) -> Boolean)?): Set<Name>
|
||||||
= memberIndex().getMethodNames(nameFilter ?: alwaysTrue())
|
= memberIndex().getMethodNames(nameFilter ?: alwaysTrue())
|
||||||
|
|
||||||
|
override fun getContributedFunctions(name: Name, location: LookupLocation): Collection<SimpleFunctionDescriptor> {
|
||||||
|
if (name !in getFunctionNames()) return emptyList()
|
||||||
|
return functions(name)
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract fun computeNonDeclaredProperties(name: Name, result: MutableCollection<PropertyDescriptor>)
|
protected abstract fun computeNonDeclaredProperties(name: Name, result: MutableCollection<PropertyDescriptor>)
|
||||||
|
|
||||||
protected abstract fun computePropertyNames(kindFilter: DescriptorKindFilter, nameFilter: ((Name) -> Boolean)?): Set<Name>
|
protected abstract fun computePropertyNames(kindFilter: DescriptorKindFilter, nameFilter: ((Name) -> Boolean)?): Set<Name>
|
||||||
@@ -289,7 +298,10 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS
|
|||||||
return propertyType
|
return propertyType
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor> = properties(name)
|
override fun getContributedVariables(name: Name, location: LookupLocation): Collection<PropertyDescriptor> {
|
||||||
|
if (name !in getVariableNames()) return emptyList()
|
||||||
|
return properties(name)
|
||||||
|
}
|
||||||
|
|
||||||
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) = allDescriptors()
|
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) = allDescriptors()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user