Skip to content

Commit

Permalink
perf: check type instead of class
Browse files Browse the repository at this point in the history
this is way better, thank you oSumAtrIX!
  • Loading branch information
Sculas authored and oSumAtrIX committed Jun 5, 2022
1 parent fa6e454 commit c7ef264
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/main/kotlin/app/revanced/patcher/resolver/MethodResolver.kt
Expand Up @@ -129,13 +129,7 @@ private fun InsnList.scanFor(pattern: IntArray): ScanResult {
var occurrence = 0
while (i + occurrence < this.size()) {
val n = this[i + occurrence]
if (
!n.anyOf(
LabelNode::class.java,
LineNumberNode::class.java
) &&
n.opcode != pattern[occurrence]
) break
if (!n.shouldSkip() && n.opcode != pattern[occurrence]) break
if (++occurrence >= pattern.size) {
val current = i + occurrence
return ScanResult(true, current - pattern.size, current)
Expand All @@ -158,5 +152,5 @@ private fun Array<Type>.convertObjects(): Array<Type> {
return this.map { it.convertObject() }.toTypedArray()
}

private fun AbstractInsnNode.anyOf(vararg types: Class<*>): Boolean =
types.any { this@anyOf.javaClass == it }
private fun AbstractInsnNode.shouldSkip() =
type == AbstractInsnNode.LABEL || type == AbstractInsnNode.LINE

0 comments on commit c7ef264

Please sign in to comment.