@@ -44,6 +44,9 @@ class ConstantArrayType extends ArrayType implements ConstantType
44
44
/** @var int[] */
45
45
private $ optionalKeys ;
46
46
47
+ /** @var self[]|null */
48
+ private $ allArrays ;
49
+
47
50
/**
48
51
* @param array<int, ConstantIntegerType|ConstantStringType> $keyTypes
49
52
* @param array<int, Type> $valueTypes
@@ -93,7 +96,19 @@ public function getOptionalKeys(): array
93
96
*/
94
97
public function getAllArrays (): array
95
98
{
96
- $ optionalKeysCombination = $ this ->powerSet ($ this ->optionalKeys );
99
+ if ($ this ->allArrays !== null ) {
100
+ return $ this ->allArrays ;
101
+ }
102
+
103
+ if (count ($ this ->optionalKeys ) <= 10 ) {
104
+ $ optionalKeysCombinations = $ this ->powerSet ($ this ->optionalKeys );
105
+ } else {
106
+ $ optionalKeysCombinations = [
107
+ [],
108
+ $ this ->optionalKeys ,
109
+ ];
110
+ }
111
+
97
112
$ requiredKeys = [];
98
113
foreach (array_keys ($ this ->keyTypes ) as $ i ) {
99
114
if (in_array ($ i , $ this ->optionalKeys , true )) {
@@ -103,7 +118,7 @@ public function getAllArrays(): array
103
118
}
104
119
105
120
$ arrays = [];
106
- foreach ($ optionalKeysCombination as $ combination ) {
121
+ foreach ($ optionalKeysCombinations as $ combination ) {
107
122
$ keys = array_merge ($ requiredKeys , $ combination );
108
123
$ keyTypes = [];
109
124
$ valueTypes = [];
@@ -115,7 +130,7 @@ public function getAllArrays(): array
115
130
$ arrays [] = new self ($ keyTypes , $ valueTypes , 0 /*TODO*/ , []);
116
131
}
117
132
118
- return $ arrays ;
133
+ return $ this -> allArrays = $ arrays ;
119
134
}
120
135
121
136
/**
0 commit comments