[compiler] replace Enum values() with entries

To fix warnings. Also, use of `Enum.entries` may improve the performance

^KT-48872
This commit is contained in:
Dmitrii Gridin
2024-02-15 00:02:32 +01:00
committed by Space Team
parent ec167d4d42
commit 072d191306
60 changed files with 174 additions and 267 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -46,7 +46,7 @@ open class BuiltinSymbolsBase(val irBuiltIns: IrBuiltIns, private val symbolTabl
val charSequence = getClass(Name.identifier("CharSequence"), "kotlin")
val string = getClass(Name.identifier("String"), "kotlin")
val primitiveIteratorsByType = PrimitiveType.values().associate { type ->
val primitiveIteratorsByType = PrimitiveType.entries.associate { type ->
val iteratorClass = getClass(Name.identifier(type.typeName.asString() + "Iterator"), "kotlin", "collections")
type to iteratorClass
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -281,7 +281,7 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
val jsArrayIteratorFunction = getInternalFunction("arrayIterator")
val jsPrimitiveArrayIteratorFunctions =
PrimitiveType.values().associate { it to getInternalFunction("${it.typeName.asString().toLowerCaseAsciiOnly()}ArrayIterator") }
PrimitiveType.entries.associate { it to getInternalFunction("${it.typeName.asString().toLowerCaseAsciiOnly()}ArrayIterator") }
val jsClass = getInternalFunction("jsClassIntrinsic")
val arrayLiteral: IrSimpleFunctionSymbol = getInternalFunction("arrayLiteral")
@@ -321,14 +321,14 @@ class JsIntrinsics(private val irBuiltIns: IrBuiltIns, val context: JsIrBackendC
)
val primitiveToSizeConstructor =
PrimitiveType.values().associate { type ->
PrimitiveType.entries.associate { type ->
type to (primitiveToTypedArrayMap[type]?.let {
getInternalFunction("${it.toLowerCaseAsciiOnly()}Array")
} ?: getInternalFunction("${type.typeName.asString().toLowerCaseAsciiOnly()}Array"))
}
val primitiveToLiteralConstructor =
PrimitiveType.values().associate { type ->
PrimitiveType.entries.associate { type ->
type to (primitiveToTypedArrayMap[type]?.let {
getInternalFunction("${it.toLowerCaseAsciiOnly()}ArrayOf")
} ?: getInternalFunction("${type.typeName.asString().toLowerCaseAsciiOnly()}ArrayOf"))
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -276,10 +276,10 @@ private class JsIrAstDeserializer(private val source: ByteArray) {
}
}
private val sideEffectKindValues = SideEffectKind.values()
private val jsBinaryOperatorValues = JsBinaryOperator.values()
private val jsUnaryOperatorValues = JsUnaryOperator.values()
private val jsFunctionModifiersValues = JsFunction.Modifier.values()
private val sideEffectKindValues get() = SideEffectKind.entries
private val jsBinaryOperatorValues get() = JsBinaryOperator.entries
private val jsUnaryOperatorValues get() = JsUnaryOperator.entries
private val jsFunctionModifiersValues get() = JsFunction.Modifier.entries
private fun readExpression(): JsExpression {
return withComments {
@@ -450,7 +450,7 @@ private class JsIrAstDeserializer(private val source: ByteArray) {
}
}
private val specialFunctionValues = SpecialFunction.values()
private val specialFunctionValues get() = SpecialFunction.entries
private fun readName(): JsName {
val identifier = stringTable[readInt()]
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -94,7 +94,7 @@ internal class VarargLowering(val context: JvmBackendContext) : FileLoweringPass
}
internal val PRIMITIVE_ARRAY_OF_NAMES: Set<String> =
(PrimitiveType.values().map { type -> type.name } + UnsignedType.values().map { type -> type.typeName.asString() })
(PrimitiveType.entries.map { type -> type.name } + UnsignedType.entries.map { type -> type.typeName.asString() })
.map { name -> name.toLowerCaseAsciiOnly() + "ArrayOf" }.toSet()
internal const val ARRAY_OF_NAME = "arrayOf"
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -444,13 +444,13 @@ class IrBuiltInsOverDescriptors(
override val booleanArray = builtIns.getPrimitiveArrayClassDescriptor(PrimitiveType.BOOLEAN).toIrSymbol()
override val primitiveArraysToPrimitiveTypes =
PrimitiveType.values().associate { builtIns.getPrimitiveArrayClassDescriptor(it).toIrSymbol() to it }
PrimitiveType.entries.associate { builtIns.getPrimitiveArrayClassDescriptor(it).toIrSymbol() to it }
override val primitiveTypesToPrimitiveArrays = primitiveArraysToPrimitiveTypes.map { (k, v) -> v to k }.toMap()
override val primitiveArrayElementTypes = primitiveArraysToPrimitiveTypes.mapValues { primitiveTypeToIrType[it.value] }
override val primitiveArrayForType = primitiveArrayElementTypes.asSequence().associate { it.value to it.key }
override val unsignedTypesToUnsignedArrays: Map<UnsignedType, IrClassSymbol> =
UnsignedType.values().mapNotNull { unsignedType ->
UnsignedType.entries.mapNotNull { unsignedType ->
val array = builtIns.builtInsModule.findClassAcrossModuleDependencies(unsignedType.arrayClassId)?.toIrSymbol()
if (array == null) null else unsignedType to array
}.toMap()
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -26,7 +26,7 @@ enum class PartialLinkageMode(val isEnabled: Boolean) {
val DEFAULT = ENABLE
fun resolveMode(key: String): PartialLinkageMode? =
values().firstOrNull { entry -> entry.name.equals(key, ignoreCase = true) }
entries.firstOrNull { entry -> entry.name.equals(key, ignoreCase = true) }
}
}
@@ -37,7 +37,7 @@ enum class PartialLinkageLogLevel {
val DEFAULT = INFO
fun resolveLogLevel(key: String): PartialLinkageLogLevel? =
values().firstOrNull { entry -> entry.name.equals(key, ignoreCase = true) }
entries.firstOrNull { entry -> entry.name.equals(key, ignoreCase = true) }
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -89,23 +89,23 @@ private fun classFqNameEquals(symbol: IrClassSymbol, fqName: FqNameUnsafe): Bool
}
private val idSignatureToPrimitiveType: Map<IdSignature.CommonSignature, PrimitiveType> =
PrimitiveType.values().associateBy {
PrimitiveType.entries.associateBy {
getPublicSignature(StandardNames.BUILT_INS_PACKAGE_FQ_NAME, it.typeName.asString())
}
private val shortNameToPrimitiveType: Map<Name, PrimitiveType> =
PrimitiveType.values().associateBy(PrimitiveType::typeName)
PrimitiveType.entries.associateBy(PrimitiveType::typeName)
private val idSignatureToUnsignedType: Map<IdSignature.CommonSignature, UnsignedType> =
UnsignedType.values().associateBy {
UnsignedType.entries.associateBy {
getPublicSignature(StandardNames.BUILT_INS_PACKAGE_FQ_NAME, it.typeName.asString())
}
private val shortNameToUnsignedType: Map<Name, UnsignedType> =
UnsignedType.values().associateBy(UnsignedType::typeName)
UnsignedType.entries.associateBy(UnsignedType::typeName)
val primitiveArrayTypesSignatures: Map<PrimitiveType, IdSignature.CommonSignature> =
PrimitiveType.values().associateWith {
PrimitiveType.entries.associateWith {
getPublicSignature(StandardNames.BUILT_INS_PACKAGE_FQ_NAME, "${it.typeName.asString()}Array")
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -305,7 +305,7 @@ sealed class IdSignature {
val nameSegments: List<String> get() = declarationFqName.split('.')
private fun adaptMask(old: Long): Long =
old xor Flags.values().fold(0L) { a, f ->
old xor Flags.entries.fold(0L) { a, f ->
if (!f.recursive) a or (old and (1L shl f.ordinal))
else a
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -48,12 +48,12 @@ internal class ClassifierExplorer(
buildSet {
this += permittedAnnotationArrayParameterSymbols
PrimitiveType.values().forEach {
PrimitiveType.entries.forEach {
addIfNotNull(builtIns.findClass(it.typeName, BUILT_INS_PACKAGE_FQ_NAME)) // kotlin.<primitive>
addIfNotNull(builtIns.findClass(it.arrayTypeName, BUILT_INS_PACKAGE_FQ_NAME)) // kotlin.<primitive>Array
}
UnsignedType.values().forEach {
UnsignedType.entries.forEach {
addIfNotNull(builtIns.findClass(it.typeName, BUILT_INS_PACKAGE_FQ_NAME)) // kotlin.U<signed>
addIfNotNull(builtIns.findClass(it.arrayClassId.shortClassName, BUILT_INS_PACKAGE_FQ_NAME)) // kotlin.U<signed>Array
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -30,7 +30,7 @@ value class BinarySymbolData(val code: Long) {
val signatureId: Int get() = (code ushr 8).toInt()
val kind: SymbolKind
get() = SymbolKind.values()[symbolKindId()]
get() = SymbolKind.entries[symbolKindId()]
companion object {
fun encode(kind: SymbolKind, signatureId: Int): Long {
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -17,7 +17,7 @@ value class BinaryTypeProjection(val code: Long) {
val variance: Variance
get() {
assert(!isStarProjection)
return Variance.values()[varianceId()]
return Variance.entries[varianceId()]
}
val typeIndex: Int get() = (code ushr 2).toInt()