From 4b96311600aa7d24f27e49b2deeb794d8c0a4afc Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Thu, 23 Nov 2017 16:16:15 +0300 Subject: [PATCH] Add faster get*Names overrides in LazyClassMemberScope --- .../lazy/descriptors/LazyClassMemberScope.kt | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassMemberScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassMemberScope.kt index 9e81b4eed20..ec39619319c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassMemberScope.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/LazyClassMemberScope.kt @@ -88,6 +88,37 @@ open class LazyClassMemberScope( return result } + private val _variableNames: MutableSet + by lazy(LazyThreadSafetyMode.PUBLICATION) { + mutableSetOf().apply { + addAll(declarationProvider.getDeclarationNames()) + thisDescriptor.typeConstructor.supertypes.flatMapTo(this) { + it.memberScope.getVariableNames() + } + } + } + + private val _functionNames: MutableSet + by lazy(LazyThreadSafetyMode.PUBLICATION) { + mutableSetOf().apply { + addAll(declarationProvider.getDeclarationNames()) + thisDescriptor.typeConstructor.supertypes.flatMapTo(this) { + it.memberScope.getFunctionNames() + } + + addAll(getDataClassRelatedFunctionNames()) + } + } + + private fun getDataClassRelatedFunctionNames(): Collection { + val declarations = mutableListOf() + addDataClassMethods(declarations, NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS) + return declarations.map { it.name } + } + + override fun getVariableNames() = _variableNames + override fun getFunctionNames() = _functionNames + private interface MemberExtractor { fun extract(extractFrom: KotlinType, name: Name): Collection }