From 6410aed1b4adf6821adb4a9781f8d1419759d407 Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Thu, 18 Jun 2020 11:26:57 +0700 Subject: [PATCH] Minor. Replace computeIfAbsent() by getOrPut() --- .../commonizer/builder/CommonizedMemberScope.kt | 4 ++-- .../builder/DeclarationsBuilderVisitor1.kt | 2 +- .../descriptors/commonizer/builder/context.kt | 4 ++-- .../commonizer/mergedtree/CirTreeMerger.kt | 14 +++++++------- .../commonizer/stats/AggregatedStatsCollector.kt | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedMemberScope.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedMemberScope.kt index c86807c0265..ca6165f28b0 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedMemberScope.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/CommonizedMemberScope.kt @@ -19,8 +19,8 @@ class CommonizedMemberScope : MemberScope { private fun addMember(member: DeclarationDescriptor) { when (member) { - is SimpleFunctionDescriptor -> functions.computeIfAbsent(member.name) { ArrayList(INITIAL_CAPACITY_FOR_CALLABLES) } += member - is PropertyDescriptor -> variables.computeIfAbsent(member.name) { ArrayList(INITIAL_CAPACITY_FOR_CALLABLES) } += member + is SimpleFunctionDescriptor -> functions.getOrPut(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 else -> error("Unsupported member type: ${member::class.java}, $member") } diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/DeclarationsBuilderVisitor1.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/DeclarationsBuilderVisitor1.kt index 995a6c40b31..8d122c94432 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/DeclarationsBuilderVisitor1.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/DeclarationsBuilderVisitor1.kt @@ -37,7 +37,7 @@ internal class DeclarationsBuilderVisitor1( val modules = moduleNode.accept(this, noContainingDeclarations()).asListContaining() modules.forEachIndexed { index, module -> val target = allTargets[index] - modulesByTargets.computeIfAbsent(target) { mutableListOf() }.addIfNotNull(module) + modulesByTargets.getOrPut(target) { mutableListOf() }.addIfNotNull(module) } } diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/context.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/context.kt index 2add8255968..153f3eb26ab 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/context.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/builder/context.kt @@ -80,7 +80,7 @@ class DeclarationsBuilderCache(private val dimension: Int) { typeAliases[fqName][index] = descriptor } - fun computeIfAbsentForwardDeclarationsModule(index: Int, computable: () -> ModuleDescriptorImpl): ModuleDescriptorImpl { + fun getOrPutForwardDeclarationsModule(index: Int, computable: () -> ModuleDescriptorImpl): ModuleDescriptorImpl { forwardDeclarationsModules[index]?.let { return it } val module = computable() @@ -140,7 +140,7 @@ class TargetDeclarationsBuilderComponents( return if (fqName.isUnderKotlinNativeSyntheticPackages) { // 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 - val module = cache.computeIfAbsentForwardDeclarationsModule(index) { + val module = cache.getOrPutForwardDeclarationsModule(index) { // N.B. forward declarations module is created only on demand createKotlinNativeForwardDeclarationsModule( storageManager = storageManager, diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirTreeMerger.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirTreeMerger.kt index ed2e847c01c..8860e80a312 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirTreeMerger.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/mergedtree/CirTreeMerger.kt @@ -62,7 +62,7 @@ class CirTreeMerger( moduleDescriptor: ModuleDescriptor ) { val moduleName: Name = moduleDescriptor.name.intern() - val moduleNode: CirModuleNode = modules.computeIfAbsent(moduleName) { + val moduleNode: CirModuleNode = modules.getOrPut(moduleName) { buildModuleNode(storageManager, size) } moduleNode.targetDeclarations[targetIndex] = CirModuleFactory.create(moduleDescriptor) @@ -81,7 +81,7 @@ class CirTreeMerger( packageMemberScope: MemberScope, moduleName: Name ) { - val packageNode: CirPackageNode = packages.computeIfAbsent(packageFqName) { + val packageNode: CirPackageNode = packages.getOrPut(packageFqName) { buildPackageNode(storageManager, size, packageFqName, moduleName) } packageNode.targetDeclarations[targetIndex] = CirPackageFactory.create(packageFqName) @@ -105,7 +105,7 @@ class CirTreeMerger( propertyDescriptor: PropertyDescriptor, parentCommonDeclaration: NullableLazyValue<*>? ) { - val propertyNode: CirPropertyNode = properties.computeIfAbsent(PropertyApproximationKey(propertyDescriptor)) { + val propertyNode: CirPropertyNode = properties.getOrPut(PropertyApproximationKey(propertyDescriptor)) { buildPropertyNode(storageManager, size, cacheRW, parentCommonDeclaration) } propertyNode.targetDeclarations[targetIndex] = CirPropertyFactory.create(propertyDescriptor) @@ -117,7 +117,7 @@ class CirTreeMerger( functionDescriptor: SimpleFunctionDescriptor, parentCommonDeclaration: NullableLazyValue<*>? ) { - val functionNode: CirFunctionNode = functions.computeIfAbsent(FunctionApproximationKey(functionDescriptor)) { + val functionNode: CirFunctionNode = functions.getOrPut(FunctionApproximationKey(functionDescriptor)) { buildFunctionNode(storageManager, size, cacheRW, parentCommonDeclaration) } functionNode.targetDeclarations[targetIndex] = CirFunctionFactory.create(functionDescriptor) @@ -129,7 +129,7 @@ class CirTreeMerger( classDescriptor: ClassDescriptor, 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()) } classNode.targetDeclarations[targetIndex] = CirClassFactory.create(classDescriptor) @@ -156,7 +156,7 @@ class CirTreeMerger( constructorDescriptor: ClassConstructorDescriptor, parentCommonDeclaration: NullableLazyValue<*>? ) { - val constructorNode: CirClassConstructorNode = constructors.computeIfAbsent(ConstructorApproximationKey(constructorDescriptor)) { + val constructorNode: CirClassConstructorNode = constructors.getOrPut(ConstructorApproximationKey(constructorDescriptor)) { buildClassConstructorNode(storageManager, size, cacheRW, parentCommonDeclaration) } constructorNode.targetDeclarations[targetIndex] = CirClassConstructorFactory.create(constructorDescriptor) @@ -167,7 +167,7 @@ class CirTreeMerger( targetIndex: Int, 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()) } typeAliasNode.targetDeclarations[targetIndex] = CirTypeAliasFactory.create(typeAliasDescriptor) diff --git a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/stats/AggregatedStatsCollector.kt b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/stats/AggregatedStatsCollector.kt index d2cd2487302..87b2ef79ca4 100644 --- a/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/stats/AggregatedStatsCollector.kt +++ b/native/commonizer/src/org/jetbrains/kotlin/descriptors/commonizer/stats/AggregatedStatsCollector.kt @@ -92,7 +92,7 @@ private class AggregatingOutput : StatsOutput { override fun writeRow(row: StatsOutput.StatsRow) { check(row is RawStatsCollector.RawStatsRow) - val aggregatedStatsRow = aggregatedStats.computeIfAbsent(row.declarationType, ::AggregatedStatsRow) + val aggregatedStatsRow = aggregatedStats.getOrPut(row.declarationType) { AggregatedStatsRow(row.declarationType) } when (row.common) { LIFTED_UP -> aggregatedStatsRow.liftedUp++ EXPECT -> aggregatedStatsRow.successfullyCommonized++