diff --git a/src/main/java/org/eu/autogex/algorithms/Minimizer.java b/src/main/java/org/eu/autogex/algorithms/Minimizer.java index b6b2c373..ee0aba6f 100644 --- a/src/main/java/org/eu/autogex/algorithms/Minimizer.java +++ b/src/main/java/org/eu/autogex/algorithms/Minimizer.java @@ -128,20 +128,25 @@ private static Map> splitGroup( // Maps the behavioral "signature" of a state to the subgroup of states sharing it Map> subGroups = new HashMap<>(); + // Optimization: Hoist map lookup and array length out of the loop + Map> transitionTable = dfa.getTransitionTable(); + int alphabetLen = alphabetArray.length; + for (State s : group) { // The signature is: "For each character, which partition do I end up in?" - int[] targets = new int[alphabetArray.length]; - Map transitions = dfa.getTransitionTable().get(s); + int[] targets = new int[alphabetLen]; + Map transitions = transitionTable.get(s); - for (int i = 0; i < alphabetArray.length; i++) { - if (transitions == null) { - targets[i] = -1; - continue; + // Optimization: Unswitch condition for trap states and use fast array fill + if (transitions == null) { + Arrays.fill(targets, -1); + } else { + for (int i = 0; i < alphabetLen; i++) { + State destination = transitions.get(alphabetArray[i]); + Integer targetPartitionId = + destination != null ? stateToPartitionId.get(destination) : null; + targets[i] = targetPartitionId != null ? targetPartitionId : -1; } - State destination = transitions.get(alphabetArray[i]); - Integer targetPartitionId = - destination != null ? stateToPartitionId.get(destination) : null; - targets[i] = targetPartitionId != null ? targetPartitionId : -1; } BehaviorSignature behaviorSignature = new BehaviorSignature(targets);