Skip to content

Commit c374bc1

Browse files
authored
Reduce number of calls to the StateSet::has() method (#16)
1 parent 2a541bf commit c374bc1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/StateSetIndex.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,13 @@ public function findMatchingStates(string $string, int $editDistance, int $trans
117117
for ($i = 1; $i <= $alphabetSize; $i++) {
118118
$newState = (int) ($state * $alphabetSize + $i);
119119

120-
if ($this->stateSet->has($newState)) {
121-
if ($i === $mappedChar) {
120+
if ($i === $mappedChar) {
121+
if ($this->stateSet->has($newState)) {
122122
// Match
123123
$statesStarC->add($newState, $cost);
124-
} elseif ($cost + 1 <= $editDistance) {
124+
}
125+
} elseif ($cost + 1 <= $editDistance) {
126+
if ($this->stateSet->has($newState)) {
125127
// Substitution
126128
$statesStarC->add($newState, $cost + 1);
127129
$substitutionStates[$i] ??= new CostAnnotatedStateSet();

0 commit comments

Comments
 (0)