From 1358d3fa10cb8ba011b6b89cfe3684ecf9849d2f Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Tue, 5 Nov 2024 14:39:06 +0100 Subject: [PATCH] perf: Use smallest lookup map for strings --- src/main/kotlin/app/revanced/patcher/Fingerprint.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/app/revanced/patcher/Fingerprint.kt b/src/main/kotlin/app/revanced/patcher/Fingerprint.kt index 94feca6..a44c00b 100644 --- a/src/main/kotlin/app/revanced/patcher/Fingerprint.kt +++ b/src/main/kotlin/app/revanced/patcher/Fingerprint.kt @@ -72,10 +72,9 @@ class Fingerprint internal constructor( internal fun matchOrNull(): Match? { if (_matchOrNull != null) return _matchOrNull - val lookupMaps = lookupMaps - - // Find the first - var match = strings?.firstNotNullOfOrNull { lookupMaps.methodsByStrings[it] }?.let { methodClasses -> + var match = strings?.mapNotNull { + lookupMaps.methodsByStrings[it] + }?.minByOrNull { it.size }?.let { methodClasses -> methodClasses.forEach { (classDef, method) -> val match = matchOrNull(classDef, method) if (match != null) return@let match @@ -83,7 +82,6 @@ class Fingerprint internal constructor( null } - if (match != null) return match classes.forEach { classDef ->