Minor. Replace computeIfAbsent() by getOrPut()
This commit is contained in:
+2
-2
@@ -19,8 +19,8 @@ class CommonizedMemberScope : MemberScope {
|
|||||||
|
|
||||||
private fun addMember(member: DeclarationDescriptor) {
|
private fun addMember(member: DeclarationDescriptor) {
|
||||||
when (member) {
|
when (member) {
|
||||||
is SimpleFunctionDescriptor -> functions.computeIfAbsent(member.name) { ArrayList(INITIAL_CAPACITY_FOR_CALLABLES) } += member
|
is SimpleFunctionDescriptor -> functions.getOrPut(member.name) { ArrayList(INITIAL_CAPACITY_FOR_CALLABLES) } += member
|
||||||
is PropertyDescriptor -> variables.computeIfAbsent(member.name) { ArrayList(INITIAL_CAPACITY_FOR_CALLABLES) } += member
|
is PropertyDescriptor -> variables.getOrPut(member.name) { ArrayList(INITIAL_CAPACITY_FOR_CALLABLES) } += member
|
||||||
is ClassifierDescriptorWithTypeParameters -> classifiers[member.name] = member
|
is ClassifierDescriptorWithTypeParameters -> classifiers[member.name] = member
|
||||||
else -> error("Unsupported member type: ${member::class.java}, $member")
|
else -> error("Unsupported member type: ${member::class.java}, $member")
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ internal class DeclarationsBuilderVisitor1(
|
|||||||
val modules = moduleNode.accept(this, noContainingDeclarations()).asListContaining<ModuleDescriptorImpl>()
|
val modules = moduleNode.accept(this, noContainingDeclarations()).asListContaining<ModuleDescriptorImpl>()
|
||||||
modules.forEachIndexed { index, module ->
|
modules.forEachIndexed { index, module ->
|
||||||
val target = allTargets[index]
|
val target = allTargets[index]
|
||||||
modulesByTargets.computeIfAbsent(target) { mutableListOf() }.addIfNotNull(module)
|
modulesByTargets.getOrPut(target) { mutableListOf() }.addIfNotNull(module)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -80,7 +80,7 @@ class DeclarationsBuilderCache(private val dimension: Int) {
|
|||||||
typeAliases[fqName][index] = descriptor
|
typeAliases[fqName][index] = descriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
fun computeIfAbsentForwardDeclarationsModule(index: Int, computable: () -> ModuleDescriptorImpl): ModuleDescriptorImpl {
|
fun getOrPutForwardDeclarationsModule(index: Int, computable: () -> ModuleDescriptorImpl): ModuleDescriptorImpl {
|
||||||
forwardDeclarationsModules[index]?.let { return it }
|
forwardDeclarationsModules[index]?.let { return it }
|
||||||
|
|
||||||
val module = computable()
|
val module = computable()
|
||||||
@@ -140,7 +140,7 @@ class TargetDeclarationsBuilderComponents(
|
|||||||
return if (fqName.isUnderKotlinNativeSyntheticPackages) {
|
return if (fqName.isUnderKotlinNativeSyntheticPackages) {
|
||||||
// that's a synthetic Kotlin/Native classifier that was exported as forward declaration in one or more modules,
|
// that's a synthetic Kotlin/Native classifier that was exported as forward declaration in one or more modules,
|
||||||
// but did not match any existing class or typealias
|
// but did not match any existing class or typealias
|
||||||
val module = cache.computeIfAbsentForwardDeclarationsModule(index) {
|
val module = cache.getOrPutForwardDeclarationsModule(index) {
|
||||||
// N.B. forward declarations module is created only on demand
|
// N.B. forward declarations module is created only on demand
|
||||||
createKotlinNativeForwardDeclarationsModule(
|
createKotlinNativeForwardDeclarationsModule(
|
||||||
storageManager = storageManager,
|
storageManager = storageManager,
|
||||||
|
|||||||
+7
-7
@@ -62,7 +62,7 @@ class CirTreeMerger(
|
|||||||
moduleDescriptor: ModuleDescriptor
|
moduleDescriptor: ModuleDescriptor
|
||||||
) {
|
) {
|
||||||
val moduleName: Name = moduleDescriptor.name.intern()
|
val moduleName: Name = moduleDescriptor.name.intern()
|
||||||
val moduleNode: CirModuleNode = modules.computeIfAbsent(moduleName) {
|
val moduleNode: CirModuleNode = modules.getOrPut(moduleName) {
|
||||||
buildModuleNode(storageManager, size)
|
buildModuleNode(storageManager, size)
|
||||||
}
|
}
|
||||||
moduleNode.targetDeclarations[targetIndex] = CirModuleFactory.create(moduleDescriptor)
|
moduleNode.targetDeclarations[targetIndex] = CirModuleFactory.create(moduleDescriptor)
|
||||||
@@ -81,7 +81,7 @@ class CirTreeMerger(
|
|||||||
packageMemberScope: MemberScope,
|
packageMemberScope: MemberScope,
|
||||||
moduleName: Name
|
moduleName: Name
|
||||||
) {
|
) {
|
||||||
val packageNode: CirPackageNode = packages.computeIfAbsent(packageFqName) {
|
val packageNode: CirPackageNode = packages.getOrPut(packageFqName) {
|
||||||
buildPackageNode(storageManager, size, packageFqName, moduleName)
|
buildPackageNode(storageManager, size, packageFqName, moduleName)
|
||||||
}
|
}
|
||||||
packageNode.targetDeclarations[targetIndex] = CirPackageFactory.create(packageFqName)
|
packageNode.targetDeclarations[targetIndex] = CirPackageFactory.create(packageFqName)
|
||||||
@@ -105,7 +105,7 @@ class CirTreeMerger(
|
|||||||
propertyDescriptor: PropertyDescriptor,
|
propertyDescriptor: PropertyDescriptor,
|
||||||
parentCommonDeclaration: NullableLazyValue<*>?
|
parentCommonDeclaration: NullableLazyValue<*>?
|
||||||
) {
|
) {
|
||||||
val propertyNode: CirPropertyNode = properties.computeIfAbsent(PropertyApproximationKey(propertyDescriptor)) {
|
val propertyNode: CirPropertyNode = properties.getOrPut(PropertyApproximationKey(propertyDescriptor)) {
|
||||||
buildPropertyNode(storageManager, size, cacheRW, parentCommonDeclaration)
|
buildPropertyNode(storageManager, size, cacheRW, parentCommonDeclaration)
|
||||||
}
|
}
|
||||||
propertyNode.targetDeclarations[targetIndex] = CirPropertyFactory.create(propertyDescriptor)
|
propertyNode.targetDeclarations[targetIndex] = CirPropertyFactory.create(propertyDescriptor)
|
||||||
@@ -117,7 +117,7 @@ class CirTreeMerger(
|
|||||||
functionDescriptor: SimpleFunctionDescriptor,
|
functionDescriptor: SimpleFunctionDescriptor,
|
||||||
parentCommonDeclaration: NullableLazyValue<*>?
|
parentCommonDeclaration: NullableLazyValue<*>?
|
||||||
) {
|
) {
|
||||||
val functionNode: CirFunctionNode = functions.computeIfAbsent(FunctionApproximationKey(functionDescriptor)) {
|
val functionNode: CirFunctionNode = functions.getOrPut(FunctionApproximationKey(functionDescriptor)) {
|
||||||
buildFunctionNode(storageManager, size, cacheRW, parentCommonDeclaration)
|
buildFunctionNode(storageManager, size, cacheRW, parentCommonDeclaration)
|
||||||
}
|
}
|
||||||
functionNode.targetDeclarations[targetIndex] = CirFunctionFactory.create(functionDescriptor)
|
functionNode.targetDeclarations[targetIndex] = CirFunctionFactory.create(functionDescriptor)
|
||||||
@@ -129,7 +129,7 @@ class CirTreeMerger(
|
|||||||
classDescriptor: ClassDescriptor,
|
classDescriptor: ClassDescriptor,
|
||||||
parentCommonDeclaration: NullableLazyValue<*>?
|
parentCommonDeclaration: NullableLazyValue<*>?
|
||||||
) {
|
) {
|
||||||
val classNode: CirClassNode = classes.computeIfAbsent(classDescriptor.name.intern()) {
|
val classNode: CirClassNode = classes.getOrPut(classDescriptor.name.intern()) {
|
||||||
buildClassNode(storageManager, size, cacheRW, parentCommonDeclaration, classDescriptor.fqNameSafe.intern())
|
buildClassNode(storageManager, size, cacheRW, parentCommonDeclaration, classDescriptor.fqNameSafe.intern())
|
||||||
}
|
}
|
||||||
classNode.targetDeclarations[targetIndex] = CirClassFactory.create(classDescriptor)
|
classNode.targetDeclarations[targetIndex] = CirClassFactory.create(classDescriptor)
|
||||||
@@ -156,7 +156,7 @@ class CirTreeMerger(
|
|||||||
constructorDescriptor: ClassConstructorDescriptor,
|
constructorDescriptor: ClassConstructorDescriptor,
|
||||||
parentCommonDeclaration: NullableLazyValue<*>?
|
parentCommonDeclaration: NullableLazyValue<*>?
|
||||||
) {
|
) {
|
||||||
val constructorNode: CirClassConstructorNode = constructors.computeIfAbsent(ConstructorApproximationKey(constructorDescriptor)) {
|
val constructorNode: CirClassConstructorNode = constructors.getOrPut(ConstructorApproximationKey(constructorDescriptor)) {
|
||||||
buildClassConstructorNode(storageManager, size, cacheRW, parentCommonDeclaration)
|
buildClassConstructorNode(storageManager, size, cacheRW, parentCommonDeclaration)
|
||||||
}
|
}
|
||||||
constructorNode.targetDeclarations[targetIndex] = CirClassConstructorFactory.create(constructorDescriptor)
|
constructorNode.targetDeclarations[targetIndex] = CirClassConstructorFactory.create(constructorDescriptor)
|
||||||
@@ -167,7 +167,7 @@ class CirTreeMerger(
|
|||||||
targetIndex: Int,
|
targetIndex: Int,
|
||||||
typeAliasDescriptor: TypeAliasDescriptor
|
typeAliasDescriptor: TypeAliasDescriptor
|
||||||
) {
|
) {
|
||||||
val typeAliasNode: CirTypeAliasNode = typeAliases.computeIfAbsent(typeAliasDescriptor.name.intern()) {
|
val typeAliasNode: CirTypeAliasNode = typeAliases.getOrPut(typeAliasDescriptor.name.intern()) {
|
||||||
buildTypeAliasNode(storageManager, size, cacheRW, typeAliasDescriptor.fqNameSafe.intern())
|
buildTypeAliasNode(storageManager, size, cacheRW, typeAliasDescriptor.fqNameSafe.intern())
|
||||||
}
|
}
|
||||||
typeAliasNode.targetDeclarations[targetIndex] = CirTypeAliasFactory.create(typeAliasDescriptor)
|
typeAliasNode.targetDeclarations[targetIndex] = CirTypeAliasFactory.create(typeAliasDescriptor)
|
||||||
|
|||||||
+1
-1
@@ -92,7 +92,7 @@ private class AggregatingOutput : StatsOutput {
|
|||||||
override fun writeRow(row: StatsOutput.StatsRow) {
|
override fun writeRow(row: StatsOutput.StatsRow) {
|
||||||
check(row is RawStatsCollector.RawStatsRow)
|
check(row is RawStatsCollector.RawStatsRow)
|
||||||
|
|
||||||
val aggregatedStatsRow = aggregatedStats.computeIfAbsent(row.declarationType, ::AggregatedStatsRow)
|
val aggregatedStatsRow = aggregatedStats.getOrPut(row.declarationType) { AggregatedStatsRow(row.declarationType) }
|
||||||
when (row.common) {
|
when (row.common) {
|
||||||
LIFTED_UP -> aggregatedStatsRow.liftedUp++
|
LIFTED_UP -> aggregatedStatsRow.liftedUp++
|
||||||
EXPECT -> aggregatedStatsRow.successfullyCommonized++
|
EXPECT -> aggregatedStatsRow.successfullyCommonized++
|
||||||
|
|||||||
Reference in New Issue
Block a user