Skip to content

Commit 2a9f636

Browse files
staabmondrejmirtes
authored andcommitted
TypeCombinator: Reduce number of intersect() calls
1 parent b9f6c80 commit 2a9f636

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/Type/TypeCombinator.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -940,12 +940,14 @@ private static function optimizeConstantArrays(array $types): array
940940
$keyType = TypeCombinator::union(...array_values($keyTypes));
941941
$valueType = TypeCombinator::union(...array_values($valueTypes));
942942

943-
$arrayType = new ArrayType($keyType, $valueType);
943+
$accessories = [];
944944
if ($isList) {
945-
$arrayType = TypeCombinator::intersect($arrayType, new AccessoryArrayListType());
945+
$accessories[] = new AccessoryArrayListType();
946946
}
947+
$accessories[] = new NonEmptyArrayType();
948+
$accessories[] = new OversizedArrayType();
947949

948-
return TypeCombinator::intersect($arrayType, new NonEmptyArrayType(), new OversizedArrayType());
950+
return TypeCombinator::intersect(new ArrayType($keyType, $valueType), ...$accessories);
949951
});
950952

951953
if (!$isOversized) {
@@ -975,12 +977,14 @@ private static function optimizeConstantArrays(array $types): array
975977
$valueType = $valueType->generalize(GeneralizePrecision::lessSpecific());
976978
}
977979

978-
$arrayType = new ArrayType($keyType, $valueType);
980+
$accessories = [];
979981
if ($eachIsList) {
980-
$arrayType = self::intersect($arrayType, new AccessoryArrayListType());
982+
$accessories[] = new AccessoryArrayListType();
981983
}
984+
$accessories[] = new NonEmptyArrayType();
985+
$accessories[] = new OversizedArrayType();
982986

983-
return [self::intersect($arrayType, new NonEmptyArrayType(), new OversizedArrayType())];
987+
return [self::intersect(new ArrayType($keyType, $valueType), ...$accessories)];
984988
}
985989

986990
return $results;

0 commit comments

Comments
 (0)