From 06b8af41e262390f54887b35d881488640055618 Mon Sep 17 00:00:00 2001 From: Graham Date: Sat, 11 Jan 2020 15:47:32 +0000 Subject: [PATCH] Replace Stream with Sequence --- asm/src/main/java/dev/openrs2/asm/InsnMatcher.kt | 9 +++------ .../openrs2/deob/transform/OpaquePredicateTransformer.kt | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/asm/src/main/java/dev/openrs2/asm/InsnMatcher.kt b/asm/src/main/java/dev/openrs2/asm/InsnMatcher.kt index ba70037912..982df6ace1 100644 --- a/asm/src/main/java/dev/openrs2/asm/InsnMatcher.kt +++ b/asm/src/main/java/dev/openrs2/asm/InsnMatcher.kt @@ -5,21 +5,18 @@ import org.objectweb.asm.tree.AbstractInsnNode import org.objectweb.asm.tree.InsnList import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.util.Printer -import java.util.stream.Stream -import kotlin.streams.asStream class InsnMatcher private constructor(private val regex: Regex) { - // TODO(gpe): use Sequence when the rest of the deobfuscator is ported to Kotlin - fun match(method: MethodNode): Stream> { + fun match(method: MethodNode): Sequence> { return match(method.instructions) } - fun match(list: InsnList): Stream> { + fun match(list: InsnList): Sequence> { val insns = list.filter { it.opcode != -1 }.toList() val codepoints = insns.map { opcodeToCodepoint(it.opcode) }.toCharArray() return regex.findAll(String(codepoints)).map { insns.subList(it.range.first, it.range.last + 1) - }.asStream() + } } companion object { 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 716f76c6ed..846072659c 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.kt +++ b/deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.kt @@ -67,10 +67,10 @@ class OpaquePredicateTransformer : Transformer() { // flow obstructor loaded via local variable val iload = load as VarInsnNode - return STORE_MATCHER.match(method).anyMatch { + return STORE_MATCHER.match(method).any { val getstatic = it[0] as FieldInsnNode val istore = it[1] as VarInsnNode - return@anyMatch isFlowObstructor(getstatic) && iload.`var` == istore.`var` + return@any isFlowObstructor(getstatic) && iload.`var` == istore.`var` } }