Skip to content

Commit ed81a56

Browse files
committed
Memoize prop_max_count
1 parent 4a25687 commit ed81a56

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Psalm/Type/Atomic/TKeyedArray.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ public function getMinCount(): int
455455
return $prop_min_count;
456456
}
457457

458+
/** @var int<1, max>|null */
459+
private ?int $prop_max_count = null;
458460
/**
459461
* Returns null if there is no upper limit.
460462
*
@@ -465,14 +467,17 @@ public function getMaxCount(): ?int
465467
if ($this->fallback_params) {
466468
return null;
467469
}
470+
if ($this->prop_max_count !== null) {
471+
return $this->prop_max_count;
472+
}
468473
$prop_max_count = 0;
469474
foreach ($this->properties as $property) {
470475
if (!$property->isNever()) {
471476
$prop_max_count++;
472477
}
473478
}
474479
assert($prop_max_count !== 0);
475-
return $prop_max_count;
480+
return $this->prop_max_count = $prop_max_count;
476481
}
477482
/**
478483
* Whether all keys are always defined (ignores unsealedness).

0 commit comments

Comments
 (0)