From 5fa9e9a6210603489a89d8d689c3942f950d0671 Mon Sep 17 00:00:00 2001 From: Major Date: Sat, 7 Mar 2020 10:57:37 +0000 Subject: [PATCH] Remove spurious toCollection calls Signed-off-by: Major --- asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt | 2 +- .../main/java/dev/openrs2/asm/classpath/AsmClassMetadata.kt | 6 +++--- .../dev/openrs2/asm/classpath/ReflectionClassMetadata.kt | 6 +++--- .../src/main/java/dev/openrs2/deob/ast/gl/GlRegistry.kt | 2 +- .../dev/openrs2/deob/analysis/ConstSourceInterpreter.kt | 2 +- .../main/java/dev/openrs2/deob/analysis/IntInterpreter.kt | 2 +- .../openrs2/deob/transform/StaticScramblingTransformer.kt | 3 +-- .../dev/openrs2/deob/transform/VisibilityTransformer.kt | 2 +- 8 files changed, 12 insertions(+), 13 deletions(-) diff --git a/asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt b/asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt index bb6556b1..8cc4c4c0 100644 --- a/asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt +++ b/asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt @@ -31,7 +31,7 @@ private fun remap(i: Int, argType: Type, localIndex: Int): Int { } private fun remapAll(indexes: List, argType: Type, localIndex: Int): MutableList { - return indexes.map { remap(it, argType, localIndex) }.toMutableList() + return indexes.mapTo(mutableListOf()) { remap(it, argType, localIndex) } } fun MethodNode.removeArgument(argIndex: Int) { diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.kt b/asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.kt index 3805db33..c1222426 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.kt +++ b/asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.kt @@ -19,13 +19,13 @@ class AsmClassMetadata( get() = clazz.superName?.let { classPath[it] ?: error("Failed to find $it on provided classpath.") } override val superInterfaces - get() = clazz.interfaces.map { classPath[it] ?: error("Failed to find $it on provided classpath.") }.toList() + get() = clazz.interfaces.map { classPath[it] ?: error("Failed to find $it on provided classpath.") } override val fields - get() = clazz.fields.map { MemberDesc(it) }.toList() + get() = clazz.fields.map(::MemberDesc) override val methods - get() = clazz.methods.map { MemberDesc(it) }.toList() + get() = clazz.methods.map(::MemberDesc) override fun getAccess(method: MemberDesc): Int? { return clazz.methods.find { it.name == method.name && it.desc == method.desc }?.access diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.kt b/asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.kt index 74fa9337..42d209c1 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.kt +++ b/asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.kt @@ -21,13 +21,13 @@ class ReflectionClassMetadata(private val classPath: ClassPath, private val claz get() = if (clazz.superclass != null) classPath[clazz.superclass.asmName]!! else null override val superInterfaces - get() = clazz.interfaces.map { classPath[it.asmName]!! }.toList() + get() = clazz.interfaces.map { classPath[it.asmName]!! } override val fields - get() = clazz.declaredFields.map { MemberDesc(it.name, Type.getDescriptor(it.type)) }.toList() + get() = clazz.declaredFields.map { MemberDesc(it.name, Type.getDescriptor(it.type)) } override val methods - get() = clazz.declaredMethods.map { MemberDesc(it.name, Type.getMethodDescriptor(it)) }.toList() + get() = clazz.declaredMethods.map { MemberDesc(it.name, Type.getMethodDescriptor(it)) } override fun getAccess(method: MemberDesc): Int? { return clazz.declaredMethods.find { it.name == method.name && Type.getMethodDescriptor(it) == method.desc } diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/gl/GlRegistry.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/gl/GlRegistry.kt index 51afa58f..a602c8ca 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/gl/GlRegistry.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/gl/GlRegistry.kt @@ -51,7 +51,7 @@ data class GlRegistry(val enums: ImmutableSetMultimap, val command val groups = groupsBuilder.asMap().mapValues { entry -> // sort by name length ascending so names with vendor suffixes come last - GlGroup(entry.key, entry.value.sortedBy { enum -> enum.name.length }.toList()) + GlGroup(entry.key, entry.value.sortedBy { enum -> enum.name.length }) } // create parameters and commands diff --git a/deob/src/main/java/dev/openrs2/deob/analysis/ConstSourceInterpreter.kt b/deob/src/main/java/dev/openrs2/deob/analysis/ConstSourceInterpreter.kt index 62c54cc9..121d0bd4 100644 --- a/deob/src/main/java/dev/openrs2/deob/analysis/ConstSourceInterpreter.kt +++ b/deob/src/main/java/dev/openrs2/deob/analysis/ConstSourceInterpreter.kt @@ -63,7 +63,7 @@ class ConstSourceInterpreter : Interpreter(Opcodes.ASM7) { insn: AbstractInsnNode, values: List ): ConstSourceValue? { - val args = values.map { it.basicValue }.toList() + val args = values.map(ConstSourceValue::basicValue) val basicValue = basicInterpreter.naryOperation(insn, args) ?: return null return ConstSourceValue.Unknown(basicValue) } diff --git a/deob/src/main/java/dev/openrs2/deob/analysis/IntInterpreter.kt b/deob/src/main/java/dev/openrs2/deob/analysis/IntInterpreter.kt index d875b187..b7cf89cd 100644 --- a/deob/src/main/java/dev/openrs2/deob/analysis/IntInterpreter.kt +++ b/deob/src/main/java/dev/openrs2/deob/analysis/IntInterpreter.kt @@ -124,7 +124,7 @@ class IntInterpreter(private val parameters: Array?>?) : Interpreter): IntValue? { - val args = values.map { it.basicValue }.toList() + val args = values.map(IntValue::basicValue) val basicValue = basicInterpreter.naryOperation(insn, args) ?: return null return IntValue.Unknown(basicValue) } diff --git a/deob/src/main/java/dev/openrs2/deob/transform/StaticScramblingTransformer.kt b/deob/src/main/java/dev/openrs2/deob/transform/StaticScramblingTransformer.kt index b5255866..ebf4b774 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/StaticScramblingTransformer.kt +++ b/deob/src/main/java/dev/openrs2/deob/transform/StaticScramblingTransformer.kt @@ -24,8 +24,7 @@ class StaticScramblingTransformer : Transformer() { val dependencies = clinit?.instructions ?.filterIsInstance() ?.filter { it.opcode == Opcodes.GETSTATIC && it.owner != owner.name } - ?.map(::MemberRef) - ?.toSet() ?: emptySet() + ?.mapTo(mutableSetOf(), ::MemberRef) ?: emptySet() } private val fieldSets = mutableMapOf() diff --git a/deob/src/main/java/dev/openrs2/deob/transform/VisibilityTransformer.kt b/deob/src/main/java/dev/openrs2/deob/transform/VisibilityTransformer.kt index a2fc79bc..8974e2a3 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/VisibilityTransformer.kt +++ b/deob/src/main/java/dev/openrs2/deob/transform/VisibilityTransformer.kt @@ -78,7 +78,7 @@ class VisibilityTransformer : Transformer() { val hasOverride = overridable && partition.count { classPath[it.owner]!!.methods.contains(MemberDesc(it)) } > 1 val abstract = method && access and Opcodes.ACC_ABSTRACT != 0 val partitionReferences = references[partition] - val partitionOwners = partition.map(MemberRef::owner).toSet() + val partitionOwners = partition.mapTo(mutableSetOf(), MemberRef::owner) // pick the weakest access level based on references in our own code val visibility = when {