From 80957aeca0e23f6c7b44cda903a63874e63c425c Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 31 Jan 2021 11:27:23 +0000 Subject: [PATCH] Add InsnList.clone() extension function Signed-off-by: Graham --- asm/src/main/kotlin/org/openrs2/asm/InsnListUtils.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/asm/src/main/kotlin/org/openrs2/asm/InsnListUtils.kt b/asm/src/main/kotlin/org/openrs2/asm/InsnListUtils.kt index 597490b6..da159fa2 100644 --- a/asm/src/main/kotlin/org/openrs2/asm/InsnListUtils.kt +++ b/asm/src/main/kotlin/org/openrs2/asm/InsnListUtils.kt @@ -2,6 +2,7 @@ package org.openrs2.asm import org.objectweb.asm.tree.AbstractInsnNode import org.objectweb.asm.tree.InsnList +import org.objectweb.asm.tree.LabelNode private val ANY_INSN = { _: AbstractInsnNode -> true } @@ -51,3 +52,11 @@ public fun InsnList.deleteExpression( remove(last) return true } + +public fun InsnList.clone(labels: Map): InsnList { + val copy = InsnList() + for (insn in this) { + copy.add(insn.clone(labels)) + } + return copy +}