File tree 1 file changed +11
-1
lines changed
1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 8
8
9
9
class StateSetIndex
10
10
{
11
+ /**
12
+ * @var array<string, int>
13
+ */
14
+ private array $ indexCache = [];
15
+
11
16
public function __construct (
12
17
private Config $ config ,
13
18
private AlphabetInterface $ alphabet ,
@@ -40,6 +45,11 @@ public function index(array $strings): array
40
45
$ assigned = [];
41
46
42
47
foreach ($ strings as $ string ) {
48
+ if (isset ($ this ->indexCache [$ string ])) {
49
+ $ assigned [$ string ] = $ this ->indexCache [$ string ];
50
+ continue ;
51
+ }
52
+
43
53
$ state = 0 ;
44
54
$ this ->loopOverEveryCharacter ($ string , function (int $ mappedChar ) use (&$ state ) {
45
55
$ newState = (int ) ($ state * $ this ->config ->getAlphabetSize () + $ mappedChar );
@@ -48,7 +58,7 @@ public function index(array $strings): array
48
58
$ state = $ newState ;
49
59
});
50
60
51
- $ assigned [$ string ] = $ state ;
61
+ $ assigned [$ string ] = $ this -> indexCache [ $ string ] = $ state ;
52
62
$ this ->stateSet ->acceptString ($ state , $ string );
53
63
}
54
64
You can’t perform that action at this time.
0 commit comments