Introduce getFunctionNames and getVariableNames into MemberScope

Also provide some basic implementation

The main purpose of these methods is optimization.
Most of the member scopes store mapping from names to descriptors
MemoizedFunction<Name, Collection<Descriptor>>

While there are 10 functions in class in average, 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:
Denis Zharkov
2016-09-08 15:40:02 +03:00
parent 8ee5f3de8f
commit b1edb01dd4
9 changed files with 82 additions and 7 deletions
@@ -70,6 +70,13 @@ class JvmPackageScope(
): Collection<DeclarationDescriptor> =
getFromAllScopes(javaScope, kotlinScopes) { it.getContributedDescriptors(kindFilter, nameFilter) }
override fun getFunctionNames() = kotlinScopes.flatMapTo(mutableSetOf()) { it.getFunctionNames() }.apply {
addAll(javaScope.getFunctionNames())
}
override fun getVariableNames() = kotlinScopes.flatMapTo(mutableSetOf()) { it.getVariableNames() }.apply {
addAll(javaScope.getVariableNames())
}
override fun printScopeStructure(p: Printer) {
p.println(javaClass.simpleName, " {")
p.pushIndent()
@@ -627,8 +627,8 @@ class LazyJavaClassMemberScope(
if (jNestedClass == null) {
val field = enumEntryIndex()[name]
if (field != null) {
val enumMemberNames: NotNullLazyValue<Collection<Name>> = c.storageManager.createLazyValue {
memberIndex().getAllFieldNames() + memberIndex().getMethodNames({ true })
val enumMemberNames: NotNullLazyValue<Set<Name>> = c.storageManager.createLazyValue {
(memberIndex().getAllFieldNames() + memberIndex().getMethodNames({ true })).toSet()
}
EnumEntrySyntheticClassDescriptor.create(
c.storageManager, ownerDescriptor, name, enumMemberNames, c.resolveAnnotations(field),