From abf803f01791d16b45d287ecf8f4e51f81269abc Mon Sep 17 00:00:00 2001 From: Graham Date: Tue, 4 Feb 2020 20:23:30 +0000 Subject: [PATCH] Replace contains() calls with the in operator These are artifacts of the Java port. --- asm/src/main/java/dev/openrs2/asm/InsnNodeUtils.kt | 6 +++--- asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt | 6 +++--- .../main/java/dev/openrs2/asm/classpath/ClassMetadata.kt | 4 ++-- .../dev/openrs2/deob/ast/transform/BitMaskTransformer.kt | 4 ++-- deob/src/main/java/dev/openrs2/deob/SignedClassUtils.kt | 2 +- deob/src/main/java/dev/openrs2/deob/remap/PrefixRemapper.kt | 2 +- deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.kt | 6 +++--- .../java/dev/openrs2/deob/transform/BitShiftTransformer.kt | 2 +- .../java/dev/openrs2/deob/transform/CounterTransformer.kt | 4 ++-- .../java/dev/openrs2/deob/transform/DummyArgTransformer.kt | 2 +- .../openrs2/deob/transform/OpaquePredicateTransformer.kt | 2 +- .../java/dev/openrs2/deob/transform/UnusedArgTransformer.kt | 4 ++-- 12 files changed, 22 insertions(+), 22 deletions(-) diff --git a/asm/src/main/java/dev/openrs2/asm/InsnNodeUtils.kt b/asm/src/main/java/dev/openrs2/asm/InsnNodeUtils.kt index bcc65f8c..566fb4b5 100644 --- a/asm/src/main/java/dev/openrs2/asm/InsnNodeUtils.kt +++ b/asm/src/main/java/dev/openrs2/asm/InsnNodeUtils.kt @@ -250,9 +250,9 @@ val AbstractInsnNode.intConstant: Int? } val AbstractInsnNode.pure: Boolean - get() = when { - PURE_OPCODES.contains(opcode) -> true - IMPURE_OPCODES.contains(opcode) -> false + get() = when (opcode) { + in PURE_OPCODES -> true + in IMPURE_OPCODES -> false else -> throw IllegalArgumentException() } diff --git a/asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt b/asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt index ef5f1046..6fad19e1 100644 --- a/asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt +++ b/asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt @@ -79,14 +79,14 @@ fun MethodNode.removeArgument(argIndex: Int) { } if (visibleLocalVariableAnnotations != null) { - visibleLocalVariableAnnotations.removeIf { it.index.contains(localIndex) } + visibleLocalVariableAnnotations.removeIf { localIndex in it.index } for (annotation in visibleLocalVariableAnnotations) { annotation.index = remapAll(annotation.index, argType, localIndex) } } if (invisibleLocalVariableAnnotations != null) { - invisibleLocalVariableAnnotations.removeIf { it.index.contains(localIndex) } + invisibleLocalVariableAnnotations.removeIf { localIndex in it.index } for (annotation in invisibleLocalVariableAnnotations) { annotation.index = remapAll(annotation.index, argType, localIndex) } @@ -133,7 +133,7 @@ fun MethodNode.removeDeadCode(owner: String) { } } - changed = changed or tryCatchBlocks.removeIf { deadLabels.contains(it.start) && deadLabels.contains(it.end) } + changed = changed or tryCatchBlocks.removeIf { it.start in deadLabels && it.end in deadLabels } } while (changed) } diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.kt b/asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.kt index 2116deba..f593af7f 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.kt +++ b/asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.kt @@ -16,7 +16,7 @@ abstract class ClassMetadata { fun isOverride(method: MemberDesc): Boolean { val superClass = this.superClass if (superClass != null) { - if (superClass.methods.contains(method)) { + if (method in superClass.methods) { return true } @@ -26,7 +26,7 @@ abstract class ClassMetadata { } for (superInterface in superInterfaces) { - if (superInterface.methods.contains(method)) { + if (method in superInterface.methods) { return true } diff --git a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/BitMaskTransformer.kt b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/BitMaskTransformer.kt index d3104603..388ad716 100644 --- a/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/BitMaskTransformer.kt +++ b/deob-ast/src/main/java/dev/openrs2/deob/ast/transform/BitMaskTransformer.kt @@ -15,7 +15,7 @@ class BitMaskTransformer : Transformer() { val left = expr.left val shamtExpr = expr.right - if (!SHIFT_OPS.contains(shiftOp) || !left.isBinaryExpr || !shamtExpr.isIntegerLiteralExpr) { + if (shiftOp !in SHIFT_OPS || !left.isBinaryExpr || !shamtExpr.isIntegerLiteralExpr) { return@walk } @@ -24,7 +24,7 @@ class BitMaskTransformer : Transformer() { val argExpr = bitwiseExpr.left var maskExpr = bitwiseExpr.right - if (!BITWISE_OPS.contains(bitwiseOp) || !maskExpr.isIntegerOrLongLiteral()) { + if (bitwiseOp !in BITWISE_OPS || !maskExpr.isIntegerOrLongLiteral()) { return@walk } diff --git a/deob/src/main/java/dev/openrs2/deob/SignedClassUtils.kt b/deob/src/main/java/dev/openrs2/deob/SignedClassUtils.kt index 6f692d1c..a38eeb93 100644 --- a/deob/src/main/java/dev/openrs2/deob/SignedClassUtils.kt +++ b/deob/src/main/java/dev/openrs2/deob/SignedClassUtils.kt @@ -82,7 +82,7 @@ object SignedClassUtils { } val name = type.className - if (loader.contains(name) && !signedClasses.contains(name)) { + if (name in loader && name !in signedClasses) { dependencies.add(name) } } diff --git a/deob/src/main/java/dev/openrs2/deob/remap/PrefixRemapper.kt b/deob/src/main/java/dev/openrs2/deob/remap/PrefixRemapper.kt index 41c4c35a..c7c3e0f2 100644 --- a/deob/src/main/java/dev/openrs2/deob/remap/PrefixRemapper.kt +++ b/deob/src/main/java/dev/openrs2/deob/remap/PrefixRemapper.kt @@ -9,7 +9,7 @@ object PrefixRemapper { val mapping = mutableMapOf() for (clazz in library) { - if (TypedRemapper.EXCLUDED_CLASSES.contains(clazz.name)) { + if (clazz.name in TypedRemapper.EXCLUDED_CLASSES) { mapping[clazz.name] = clazz.name } else { mapping[clazz.name] = prefix + clazz.name diff --git a/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.kt b/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.kt index eea71303..4bb7aa1b 100644 --- a/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.kt +++ b/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.kt @@ -103,7 +103,7 @@ class TypedRemapper private constructor( clazz: ClassMetadata ): String { val name = clazz.name - if (mapping.containsKey(name) || EXCLUDED_CLASSES.contains(name) || clazz.dependency) { + if (mapping.containsKey(name) || name in EXCLUDED_CLASSES || clazz.dependency) { return mapping.getOrDefault(name, name) } @@ -138,7 +138,7 @@ class TypedRemapper private constructor( for ((owner, name) in partition) { val clazz = classPath[owner] - if (EXCLUDED_FIELDS.contains(name)) { + if (name in EXCLUDED_FIELDS) { skip = true break } @@ -188,7 +188,7 @@ class TypedRemapper private constructor( for (method in partition) { val clazz = classPath[method.owner] - if (EXCLUDED_METHODS.contains(method.name)) { + if (method.name in EXCLUDED_METHODS) { return true } diff --git a/deob/src/main/java/dev/openrs2/deob/transform/BitShiftTransformer.kt b/deob/src/main/java/dev/openrs2/deob/transform/BitShiftTransformer.kt index adf0e9e7..4ff0e26c 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/BitShiftTransformer.kt +++ b/deob/src/main/java/dev/openrs2/deob/transform/BitShiftTransformer.kt @@ -29,7 +29,7 @@ class BitShiftTransformer : Transformer() { val bits = push.intConstant!! val opcode = match[1].opcode - val mask = if (LONG_SHIFTS.contains(opcode)) 63 else 31 + val mask = if (opcode in LONG_SHIFTS) 63 else 31 val simplifiedBits = bits and mask diff --git a/deob/src/main/java/dev/openrs2/deob/transform/CounterTransformer.kt b/deob/src/main/java/dev/openrs2/deob/transform/CounterTransformer.kt index a90f8908..6dc1d826 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/CounterTransformer.kt +++ b/deob/src/main/java/dev/openrs2/deob/transform/CounterTransformer.kt @@ -94,7 +94,7 @@ class CounterTransformer : Transformer() { ): Boolean { for (match in RESET_PATTERN.match(method)) { val putstatic = match[1] as FieldInsnNode - if (counters.contains(MemberRef(putstatic))) { + if (MemberRef(putstatic) in counters) { match.forEach(method.instructions::remove) } } @@ -102,7 +102,7 @@ class CounterTransformer : Transformer() { for (match in INCREMENT_PATTERN.match(method)) { val getstatic = MemberRef(match[0] as FieldInsnNode) val putstatic = MemberRef(match[3] as FieldInsnNode) - if (getstatic == putstatic && counters.contains(putstatic)) { + if (getstatic == putstatic && putstatic in counters) { match.forEach(method.instructions::remove) } } diff --git a/deob/src/main/java/dev/openrs2/deob/transform/DummyArgTransformer.kt b/deob/src/main/java/dev/openrs2/deob/transform/DummyArgTransformer.kt index 054ffd8b..528f11f0 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/DummyArgTransformer.kt +++ b/deob/src/main/java/dev/openrs2/deob/transform/DummyArgTransformer.kt @@ -311,7 +311,7 @@ class DummyArgTransformer : Transformer() { } for ((insn, value) in constInsns) { - if (!method.instructions.contains(insn)) { + if (insn !in method.instructions) { continue } diff --git a/deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.kt b/deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.kt index 04b0c4e1..672cdd81 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.kt +++ b/deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.kt @@ -54,7 +54,7 @@ class OpaquePredicateTransformer : Transformer() { } private fun isFlowObstructor(insn: FieldInsnNode): Boolean { - return flowObstructors.contains(MemberRef(insn)) + return MemberRef(insn) in flowObstructors } private fun isOpaquePredicate(method: MethodNode, match: List): Boolean { diff --git a/deob/src/main/java/dev/openrs2/deob/transform/UnusedArgTransformer.kt b/deob/src/main/java/dev/openrs2/deob/transform/UnusedArgTransformer.kt index 8d4d6183..aadde470 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/UnusedArgTransformer.kt +++ b/deob/src/main/java/dev/openrs2/deob/transform/UnusedArgTransformer.kt @@ -122,7 +122,7 @@ class UnusedArgTransformer : Transformer() { val newArgTypes = mutableListOf() for ((j, argType) in argTypes.withIndex()) { - if (INT_SORTS.contains(argType.sort) && !retainedArgs.contains(ArgRef(partition, j))) { + if (argType.sort in INT_SORTS && ArgRef(partition, j) !in retainedArgs) { val value = frame.getStack(stackSize - argTypes.size + j) as ConstSourceValue.Single deadInsns.add(value.source) } else { @@ -152,7 +152,7 @@ class UnusedArgTransformer : Transformer() { val argTypes = Type.getType(method.desc).argumentTypes for ((i, argType) in argTypes.withIndex().reversed()) { - if (INT_SORTS.contains(argType.sort) && !retainedArgs.contains(ArgRef(partition, i))) { + if (argType.sort in INT_SORTS && ArgRef(partition, i) !in retainedArgs) { method.removeArgument(i) deletedArgs++ }