[Commonizer] Replace j.u.HashMap by g.t.THashMap to reduce memory usage
This commit is contained in:
@@ -20,6 +20,7 @@ dependencies {
|
||||
compileOnly(project(":native:frontend.native"))
|
||||
compileOnly(project(":kotlin-util-klib-metadata"))
|
||||
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
||||
compileOnly(intellijDep()) { includeJars("trove4j") }
|
||||
|
||||
// This dependency is necessary to keep the right dependency record inside of POM file:
|
||||
publishedCompile(project(":kotlin-compiler"))
|
||||
|
||||
+4
-3
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.commonizer.builder
|
||||
|
||||
import gnu.trove.THashMap
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -13,9 +14,9 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
|
||||
class CommonizedMemberScope : MemberScope {
|
||||
private val functions = HashMap<Name, MutableList<SimpleFunctionDescriptor>>()
|
||||
private val variables = HashMap<Name, MutableList<PropertyDescriptor>>()
|
||||
private val classifiers = HashMap<Name, ClassifierDescriptorWithTypeParameters>()
|
||||
private val functions = THashMap<Name, MutableList<SimpleFunctionDescriptor>>()
|
||||
private val variables = THashMap<Name, MutableList<PropertyDescriptor>>()
|
||||
private val classifiers = THashMap<Name, ClassifierDescriptorWithTypeParameters>()
|
||||
|
||||
private fun addMember(member: DeclarationDescriptor) {
|
||||
when (member) {
|
||||
|
||||
+3
-2
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.commonizer.cir.factory
|
||||
|
||||
import gnu.trove.THashMap
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirAnnotation
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.impl.CirAnnotationImpl
|
||||
@@ -26,8 +27,8 @@ object CirAnnotationFactory {
|
||||
if (allValueArguments.isEmpty())
|
||||
return create(fqName = fqName, constantValueArguments = emptyMap(), annotationValueArguments = emptyMap())
|
||||
|
||||
val constantValueArguments: MutableMap<Name, ConstantValue<*>> = HashMap()
|
||||
val annotationValueArguments: MutableMap<Name, CirAnnotation> = HashMap()
|
||||
val constantValueArguments: MutableMap<Name, ConstantValue<*>> = THashMap()
|
||||
val annotationValueArguments: MutableMap<Name, CirAnnotation> = THashMap()
|
||||
|
||||
allValueArguments.forEach { (name, constantValue) ->
|
||||
checkConstantSupportedInCommonization(
|
||||
|
||||
+2
-1
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.commonizer.konan
|
||||
|
||||
import gnu.trove.THashMap
|
||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||
|
||||
internal interface NativeManifestDataProvider {
|
||||
@@ -66,4 +67,4 @@ internal class CommonNativeManifestDataProvider(
|
||||
}
|
||||
|
||||
private fun NativeDistributionLibraries.buildManifestIndex(): MutableMap<String, NativeSensitiveManifestData> =
|
||||
(platformLibs + stdlib).map { it.manifestData }.associateByTo(HashMap()) { it.uniqueName }
|
||||
(platformLibs + stdlib).map { it.manifestData }.associateByTo(THashMap()) { it.uniqueName }
|
||||
|
||||
+1
-1
@@ -63,6 +63,6 @@ internal class NativeDistributionModulesProvider(
|
||||
module.setDependencies(listOf(module) + dependencies + forwardDeclarations)
|
||||
}
|
||||
|
||||
return platformModulesMap.values
|
||||
return platformModulesMap.values.toList()
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree
|
||||
|
||||
import gnu.trove.THashMap
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirClass
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -17,10 +18,10 @@ class CirClassNode(
|
||||
override val fqName: FqName
|
||||
) : CirNodeWithFqName<CirClass, CirClass> {
|
||||
|
||||
val constructors: MutableMap<ConstructorApproximationKey, CirClassConstructorNode> = HashMap()
|
||||
val properties: MutableMap<PropertyApproximationKey, CirPropertyNode> = HashMap()
|
||||
val functions: MutableMap<FunctionApproximationKey, CirFunctionNode> = HashMap()
|
||||
val classes: MutableMap<Name, CirClassNode> = HashMap()
|
||||
val constructors: MutableMap<ConstructorApproximationKey, CirClassConstructorNode> = THashMap()
|
||||
val properties: MutableMap<PropertyApproximationKey, CirPropertyNode> = THashMap()
|
||||
val functions: MutableMap<FunctionApproximationKey, CirFunctionNode> = THashMap()
|
||||
val classes: MutableMap<Name, CirClassNode> = THashMap()
|
||||
|
||||
override fun <R, T> accept(visitor: CirNodeVisitor<R, T>, data: T): R =
|
||||
visitor.visitClassNode(this, data)
|
||||
|
||||
+2
-1
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree
|
||||
|
||||
import gnu.trove.THashMap
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirModule
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -14,7 +15,7 @@ class CirModuleNode(
|
||||
override val targetDeclarations: CommonizedGroup<CirModule>,
|
||||
override val commonDeclaration: NullableLazyValue<CirModule>
|
||||
) : CirNode<CirModule, CirModule> {
|
||||
val packages: MutableMap<FqName, CirPackageNode> = HashMap()
|
||||
val packages: MutableMap<FqName, CirPackageNode> = THashMap()
|
||||
|
||||
override fun <R, T> accept(visitor: CirNodeVisitor<R, T>, data: T) =
|
||||
visitor.visitModuleNode(this, data)
|
||||
|
||||
+5
-4
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree
|
||||
|
||||
import gnu.trove.THashMap
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirPackage
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -18,10 +19,10 @@ class CirPackageNode(
|
||||
val moduleName: Name
|
||||
) : CirNodeWithFqName<CirPackage, CirPackage> {
|
||||
|
||||
val properties: MutableMap<PropertyApproximationKey, CirPropertyNode> = HashMap()
|
||||
val functions: MutableMap<FunctionApproximationKey, CirFunctionNode> = HashMap()
|
||||
val classes: MutableMap<Name, CirClassNode> = HashMap()
|
||||
val typeAliases: MutableMap<Name, CirTypeAliasNode> = HashMap()
|
||||
val properties: MutableMap<PropertyApproximationKey, CirPropertyNode> = THashMap()
|
||||
val functions: MutableMap<FunctionApproximationKey, CirFunctionNode> = THashMap()
|
||||
val classes: MutableMap<Name, CirClassNode> = THashMap()
|
||||
val typeAliases: MutableMap<Name, CirTypeAliasNode> = THashMap()
|
||||
|
||||
override fun <R, T> accept(visitor: CirNodeVisitor<R, T>, data: T) =
|
||||
visitor.visitPackageNode(this, data)
|
||||
|
||||
+4
-3
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.commonizer.mergedtree
|
||||
|
||||
import gnu.trove.THashMap
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.cir.CirRoot
|
||||
import org.jetbrains.kotlin.descriptors.commonizer.utils.CommonizedGroup
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -16,11 +17,11 @@ class CirRootNode(
|
||||
override val commonDeclaration: NullableLazyValue<CirRoot>
|
||||
) : CirNode<CirRoot, CirRoot> {
|
||||
class CirClassifiersCacheImpl : CirClassifiersCache {
|
||||
override val classes = HashMap<FqName, CirClassNode>()
|
||||
override val typeAliases = HashMap<FqName, CirTypeAliasNode>()
|
||||
override val classes = THashMap<FqName, CirClassNode>()
|
||||
override val typeAliases = THashMap<FqName, CirTypeAliasNode>()
|
||||
}
|
||||
|
||||
val modules: MutableMap<Name, CirModuleNode> = HashMap()
|
||||
val modules: MutableMap<Name, CirModuleNode> = THashMap()
|
||||
val cache = CirClassifiersCacheImpl()
|
||||
|
||||
override fun <R, T> accept(visitor: CirNodeVisitor<R, T>, data: T): R =
|
||||
|
||||
+3
-1
@@ -5,6 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.commonizer.utils
|
||||
|
||||
import gnu.trove.THashMap
|
||||
|
||||
/** Fixed-size ordered collection with no extra space that represents a commonized group of same-rank elements */
|
||||
class CommonizedGroup<T : Any>(
|
||||
override val size: Int,
|
||||
@@ -32,7 +34,7 @@ class CommonizedGroup<T : Any>(
|
||||
}
|
||||
|
||||
internal class CommonizedGroupMap<K, V : Any>(val size: Int) : Iterable<Map.Entry<K, CommonizedGroup<V>>> {
|
||||
private val wrapped: MutableMap<K, CommonizedGroup<V>> = HashMap()
|
||||
private val wrapped: MutableMap<K, CommonizedGroup<V>> = THashMap()
|
||||
|
||||
operator fun get(key: K): CommonizedGroup<V> = wrapped.getOrPut(key) { CommonizedGroup(size) }
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.commonizer.utils
|
||||
|
||||
import gnu.trove.THashMap
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
||||
|
||||
internal fun <T> Sequence<T>.toList(expectedCapacity: Int): List<T> {
|
||||
@@ -17,7 +18,7 @@ internal infix fun <K, V> Map<K, V>.concat(other: Map<K, V>): Map<K, V> =
|
||||
when {
|
||||
isEmpty() -> other
|
||||
other.isEmpty() -> this
|
||||
else -> HashMap<K, V>(size + other.size, 1F).apply {
|
||||
else -> THashMap<K, V>(size + other.size, 1F).apply {
|
||||
putAll(this@concat)
|
||||
putAll(other)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user