Replace contains() calls with the in operator

These are artifacts of the Java port.
bzip2
Graham 5 years ago
parent 701b162dec
commit abf803f017
  1. 6
      asm/src/main/java/dev/openrs2/asm/InsnNodeUtils.kt
  2. 6
      asm/src/main/java/dev/openrs2/asm/MethodNodeUtils.kt
  3. 4
      asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.kt
  4. 4
      deob-ast/src/main/java/dev/openrs2/deob/ast/transform/BitMaskTransformer.kt
  5. 2
      deob/src/main/java/dev/openrs2/deob/SignedClassUtils.kt
  6. 2
      deob/src/main/java/dev/openrs2/deob/remap/PrefixRemapper.kt
  7. 6
      deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.kt
  8. 2
      deob/src/main/java/dev/openrs2/deob/transform/BitShiftTransformer.kt
  9. 4
      deob/src/main/java/dev/openrs2/deob/transform/CounterTransformer.kt
  10. 2
      deob/src/main/java/dev/openrs2/deob/transform/DummyArgTransformer.kt
  11. 2
      deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.kt
  12. 4
      deob/src/main/java/dev/openrs2/deob/transform/UnusedArgTransformer.kt

@ -250,9 +250,9 @@ val AbstractInsnNode.intConstant: Int?
} }
val AbstractInsnNode.pure: Boolean val AbstractInsnNode.pure: Boolean
get() = when { get() = when (opcode) {
PURE_OPCODES.contains(opcode) -> true in PURE_OPCODES -> true
IMPURE_OPCODES.contains(opcode) -> false in IMPURE_OPCODES -> false
else -> throw IllegalArgumentException() else -> throw IllegalArgumentException()
} }

@ -79,14 +79,14 @@ fun MethodNode.removeArgument(argIndex: Int) {
} }
if (visibleLocalVariableAnnotations != null) { if (visibleLocalVariableAnnotations != null) {
visibleLocalVariableAnnotations.removeIf { it.index.contains(localIndex) } visibleLocalVariableAnnotations.removeIf { localIndex in it.index }
for (annotation in visibleLocalVariableAnnotations) { for (annotation in visibleLocalVariableAnnotations) {
annotation.index = remapAll(annotation.index, argType, localIndex) annotation.index = remapAll(annotation.index, argType, localIndex)
} }
} }
if (invisibleLocalVariableAnnotations != null) { if (invisibleLocalVariableAnnotations != null) {
invisibleLocalVariableAnnotations.removeIf { it.index.contains(localIndex) } invisibleLocalVariableAnnotations.removeIf { localIndex in it.index }
for (annotation in invisibleLocalVariableAnnotations) { for (annotation in invisibleLocalVariableAnnotations) {
annotation.index = remapAll(annotation.index, argType, localIndex) 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) } while (changed)
} }

@ -16,7 +16,7 @@ abstract class ClassMetadata {
fun isOverride(method: MemberDesc): Boolean { fun isOverride(method: MemberDesc): Boolean {
val superClass = this.superClass val superClass = this.superClass
if (superClass != null) { if (superClass != null) {
if (superClass.methods.contains(method)) { if (method in superClass.methods) {
return true return true
} }
@ -26,7 +26,7 @@ abstract class ClassMetadata {
} }
for (superInterface in superInterfaces) { for (superInterface in superInterfaces) {
if (superInterface.methods.contains(method)) { if (method in superInterface.methods) {
return true return true
} }

@ -15,7 +15,7 @@ class BitMaskTransformer : Transformer() {
val left = expr.left val left = expr.left
val shamtExpr = expr.right val shamtExpr = expr.right
if (!SHIFT_OPS.contains(shiftOp) || !left.isBinaryExpr || !shamtExpr.isIntegerLiteralExpr) { if (shiftOp !in SHIFT_OPS || !left.isBinaryExpr || !shamtExpr.isIntegerLiteralExpr) {
return@walk return@walk
} }
@ -24,7 +24,7 @@ class BitMaskTransformer : Transformer() {
val argExpr = bitwiseExpr.left val argExpr = bitwiseExpr.left
var maskExpr = bitwiseExpr.right var maskExpr = bitwiseExpr.right
if (!BITWISE_OPS.contains(bitwiseOp) || !maskExpr.isIntegerOrLongLiteral()) { if (bitwiseOp !in BITWISE_OPS || !maskExpr.isIntegerOrLongLiteral()) {
return@walk return@walk
} }

@ -82,7 +82,7 @@ object SignedClassUtils {
} }
val name = type.className val name = type.className
if (loader.contains(name) && !signedClasses.contains(name)) { if (name in loader && name !in signedClasses) {
dependencies.add(name) dependencies.add(name)
} }
} }

@ -9,7 +9,7 @@ object PrefixRemapper {
val mapping = mutableMapOf<String, String>() val mapping = mutableMapOf<String, String>()
for (clazz in library) { for (clazz in library) {
if (TypedRemapper.EXCLUDED_CLASSES.contains(clazz.name)) { if (clazz.name in TypedRemapper.EXCLUDED_CLASSES) {
mapping[clazz.name] = clazz.name mapping[clazz.name] = clazz.name
} else { } else {
mapping[clazz.name] = prefix + clazz.name mapping[clazz.name] = prefix + clazz.name

@ -103,7 +103,7 @@ class TypedRemapper private constructor(
clazz: ClassMetadata clazz: ClassMetadata
): String { ): String {
val name = clazz.name 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) return mapping.getOrDefault(name, name)
} }
@ -138,7 +138,7 @@ class TypedRemapper private constructor(
for ((owner, name) in partition) { for ((owner, name) in partition) {
val clazz = classPath[owner] val clazz = classPath[owner]
if (EXCLUDED_FIELDS.contains(name)) { if (name in EXCLUDED_FIELDS) {
skip = true skip = true
break break
} }
@ -188,7 +188,7 @@ class TypedRemapper private constructor(
for (method in partition) { for (method in partition) {
val clazz = classPath[method.owner] val clazz = classPath[method.owner]
if (EXCLUDED_METHODS.contains(method.name)) { if (method.name in EXCLUDED_METHODS) {
return true return true
} }

@ -29,7 +29,7 @@ class BitShiftTransformer : Transformer() {
val bits = push.intConstant!! val bits = push.intConstant!!
val opcode = match[1].opcode 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 val simplifiedBits = bits and mask

@ -94,7 +94,7 @@ class CounterTransformer : Transformer() {
): Boolean { ): Boolean {
for (match in RESET_PATTERN.match(method)) { for (match in RESET_PATTERN.match(method)) {
val putstatic = match[1] as FieldInsnNode val putstatic = match[1] as FieldInsnNode
if (counters.contains(MemberRef(putstatic))) { if (MemberRef(putstatic) in counters) {
match.forEach(method.instructions::remove) match.forEach(method.instructions::remove)
} }
} }
@ -102,7 +102,7 @@ class CounterTransformer : Transformer() {
for (match in INCREMENT_PATTERN.match(method)) { for (match in INCREMENT_PATTERN.match(method)) {
val getstatic = MemberRef(match[0] as FieldInsnNode) val getstatic = MemberRef(match[0] as FieldInsnNode)
val putstatic = MemberRef(match[3] 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) match.forEach(method.instructions::remove)
} }
} }

@ -311,7 +311,7 @@ class DummyArgTransformer : Transformer() {
} }
for ((insn, value) in constInsns) { for ((insn, value) in constInsns) {
if (!method.instructions.contains(insn)) { if (insn !in method.instructions) {
continue continue
} }

@ -54,7 +54,7 @@ class OpaquePredicateTransformer : Transformer() {
} }
private fun isFlowObstructor(insn: FieldInsnNode): Boolean { private fun isFlowObstructor(insn: FieldInsnNode): Boolean {
return flowObstructors.contains(MemberRef(insn)) return MemberRef(insn) in flowObstructors
} }
private fun isOpaquePredicate(method: MethodNode, match: List<AbstractInsnNode>): Boolean { private fun isOpaquePredicate(method: MethodNode, match: List<AbstractInsnNode>): Boolean {

@ -122,7 +122,7 @@ class UnusedArgTransformer : Transformer() {
val newArgTypes = mutableListOf<Type>() val newArgTypes = mutableListOf<Type>()
for ((j, argType) in argTypes.withIndex()) { 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 val value = frame.getStack(stackSize - argTypes.size + j) as ConstSourceValue.Single
deadInsns.add(value.source) deadInsns.add(value.source)
} else { } else {
@ -152,7 +152,7 @@ class UnusedArgTransformer : Transformer() {
val argTypes = Type.getType(method.desc).argumentTypes val argTypes = Type.getType(method.desc).argumentTypes
for ((i, argType) in argTypes.withIndex().reversed()) { 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) method.removeArgument(i)
deletedArgs++ deletedArgs++
} }

Loading…
Cancel
Save