Skip to content

Commit 38953dd

Browse files
committed
Trying out an optimization idea
1 parent 5b448a7 commit 38953dd

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

‎src/Type/TypeCombinator.php‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -651,22 +651,37 @@ private static function processArrayTypes(array $arrayTypes, array $accessoryTyp
651651
*/
652652
private static function optimizeConstantArrays(array $types): array
653653
{
654-
$results = [];
655654
$constantArrayValuesCount = 0;
656655
foreach ($types as $type) {
657-
$results[] = TypeTraverser::map($type, static function (Type $type, callable $traverse) use (&$constantArrayValuesCount): Type {
656+
if ($type instanceof ConstantArrayType) {
657+
$constantArrayValuesCount += count($type->getValueTypes());
658+
}
659+
660+
TypeTraverser::map($type, static function (Type $type, callable $traverse) use (&$constantArrayValuesCount): Type {
658661
if ($type instanceof ConstantArrayType) {
659-
if ($constantArrayValuesCount > ConstantArrayTypeBuilder::ARRAY_COUNT_LIMIT) {
660-
return $type->generalize(GeneralizePrecision::moreSpecific());
661-
}
662662
$constantArrayValuesCount += count($type->getValueTypes());
663663
}
664664

665665
return $traverse($type);
666666
});
667667
}
668668

669-
return $results;
669+
if ($constantArrayValuesCount > ConstantArrayTypeBuilder::ARRAY_COUNT_LIMIT) {
670+
$results = [];
671+
foreach ($types as $type) {
672+
$results[] = TypeTraverser::map($type, static function (Type $type, callable $traverse): Type {
673+
if ($type instanceof ConstantArrayType) {
674+
return $type->generalize(GeneralizePrecision::moreSpecific());
675+
}
676+
677+
return $traverse($type);
678+
});
679+
}
680+
681+
return $results;
682+
}
683+
684+
return $types;
670685
}
671686

672687
/**

0 commit comments

Comments
 (0)