Skip to content

Commit

Permalink
TypeSpecifier micro-optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Dec 11, 2022
1 parent 94c841a commit 30e6d19
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Analyser/TypeSpecifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -1498,14 +1498,14 @@ private function createForExpr(
{
if ($scope !== null) {
if ($context->true()) {
$resultType = TypeCombinator::intersect($scope->getType($expr), $type);
$containsNull = TypeCombinator::containsNull($type) && TypeCombinator::containsNull($scope->getType($expr));
} elseif ($context->false()) {
$resultType = TypeCombinator::remove($scope->getType($expr), $type);
$containsNull = !TypeCombinator::containsNull($type) && TypeCombinator::containsNull($scope->getType($expr));
}
}

$originalExpr = $expr;
if (isset($resultType) && !TypeCombinator::containsNull($resultType)) {
if (isset($containsNull) && !$containsNull) {
$expr = NullsafeOperatorHelper::getNullsafeShortcircuitedExpr($expr);
}

Expand Down Expand Up @@ -1554,7 +1554,7 @@ private function createForExpr(
|| $methodReflection->hasSideEffects()->yes()
|| (!$this->rememberPossiblyImpureFunctionValues && !$methodReflection->hasSideEffects()->no())
) {
if (isset($resultType) && !TypeCombinator::containsNull($resultType)) {
if (isset($containsNull) && !$containsNull) {
return $this->createNullsafeTypes($rootExpr, $originalExpr, $scope, $context, $overwrite, $type);
}

Expand All @@ -1580,7 +1580,7 @@ private function createForExpr(
|| $methodReflection->hasSideEffects()->yes()
|| (!$this->rememberPossiblyImpureFunctionValues && !$methodReflection->hasSideEffects()->no())
) {
if (isset($resultType) && !TypeCombinator::containsNull($resultType)) {
if (isset($containsNull) && !$containsNull) {
return $this->createNullsafeTypes($rootExpr, $originalExpr, $scope, $context, $overwrite, $type);
}

Expand All @@ -1605,7 +1605,7 @@ private function createForExpr(
}

$types = new SpecifiedTypes($sureTypes, $sureNotTypes, $overwrite, [], $rootExpr);
if ($scope !== null && isset($resultType) && !TypeCombinator::containsNull($resultType)) {
if ($scope !== null && isset($containsNull) && !$containsNull) {
return $this->createNullsafeTypes($rootExpr, $originalExpr, $scope, $context, $overwrite, $type)->unionWith($types);
}

Expand Down

0 comments on commit 30e6d19

Please sign in to comment.