diff --git a/README.md b/README.md
index c90c711..d4c7707 100644
--- a/README.md
+++ b/README.md
@@ -77,6 +77,7 @@ make it work with JUnit 5. Feel free to use the code (in package ```de.platon42.
- Cosmetics: Changed Register Flow Documentation wording from _reads_ to _uses_ and from _modifies_ to _changes_.
- Bugfix: Minor fix for `andi/eori/ori to ccr` which were not byte sized in ISA.
- Bugfix: Added alternate condition code tests `HS (=CC)` and `LO (=CS)`.
+- Performance: Optimized mnemonic lookup.
### V0.4 (03-Aug-21)
diff --git a/build.gradle b/build.gradle
index 2bfe217..889afa6 100644
--- a/build.gradle
+++ b/build.gradle
@@ -63,6 +63,7 @@ patchPluginXml {
Cosmetics: Changed Register Flow Documentation wording from 'reads' to 'uses' and from 'modifies' to 'changes'.
Bugfix: Minor fix for `andi/eori/ori to ccr` which were not byte sized in ISA.
Bugfix: Added alternate condition code tests HS (=CC) and LO (=CS).
+ Performance: Optimized mnemonic lookup.
V0.4 (03-Aug-21)
diff --git a/src/main/java/de/platon42/intellij/plugins/m68k/asm/M68kIsa.kt b/src/main/java/de/platon42/intellij/plugins/m68k/asm/M68kIsa.kt
index 23744b9..0497c69 100644
--- a/src/main/java/de/platon42/intellij/plugins/m68k/asm/M68kIsa.kt
+++ b/src/main/java/de/platon42/intellij/plugins/m68k/asm/M68kIsa.kt
@@ -1002,29 +1002,19 @@ object M68kIsa {
)
)
- val mnemonics =
- isaData.asSequence()
- .flatMap {
- if (it.conditionCodes.isEmpty()) it.altMnemonics.plus(it.mnemonic) else it.altMnemonics.plus(it.conditionCodes
- .map { cc ->
- it.mnemonic.replace("CC", cc)
- })
- }
- .toSet()
+ private val mnemonicLookupMap = isaData.asSequence()
+ .flatMap {
+ (if (it.conditionCodes.isEmpty()) it.altMnemonics.plus(it.mnemonic) else it.altMnemonics.plus(it.conditionCodes
+ .map { cc ->
+ it.mnemonic.replace("CC", cc)
+ })).map { mnemonic -> mnemonic to it }
+ }
+ .groupBy({ it.first }) { it.second }
+
+ val mnemonics = mnemonicLookupMap.keys
fun findMatchingInstructions(mnemonic: String): List {
- val lowerMnemonic = mnemonic.lowercase()
- return isaData
- .filter {
- if (it.conditionCodes.isEmpty()) {
- (it.mnemonic == lowerMnemonic) || it.altMnemonics.any { altMnemonic -> altMnemonic == lowerMnemonic }
- } else {
- it.altMnemonics.any { altMnemonic -> altMnemonic == lowerMnemonic } ||
- it.conditionCodes.any { cc ->
- it.mnemonic.replace("CC", cc) == lowerMnemonic
- }
- }
- }
+ return mnemonicLookupMap.getOrDefault(mnemonic.lowercase(), emptyList())
}
fun findMatchingOpMode(candidates: List, op1: AddressMode?, op2: AddressMode?, opSize: Int?, specialReg: String?): List {