Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/Type/TypeCombinator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1624,10 +1624,17 @@ public static function doIntersect(Type ...$types): Type
return $types[0];
}

// The comparator only orders UnionTypes relative to each other, so sorting is
// a no-op unless there are at least two of them. Skip it in the common case.
$unionTypesCount = 0;
foreach ($types as $type) {
if ($type instanceof NeverType && !$type->isExplicit()) {
return $type;
}
if (!$type instanceof UnionType) {
continue;
}
$unionTypesCount++;
}

// Fast path: the intersection of two plain unions whose members are all finite,
Expand Down Expand Up @@ -1667,18 +1674,6 @@ public static function doIntersect(Type ...$types): Type

return 0;
};
// The comparator only orders UnionTypes relative to each other, so sorting is
// a no-op unless there are at least two of them. Skip it in the common case.
$unionTypesCount = 0;
foreach ($types as $type) {
if (!$type instanceof UnionType) {
continue;
}
$unionTypesCount++;
if ($unionTypesCount >= 2) {
break;
}
}
Comment on lines -1673 to -1681

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merges this loop into the above one so we don't need to run thru all types another time

if ($unionTypesCount >= 2) {
usort($types, $sortTypes);
}
Expand Down
Loading