From 5ffeef985b0d1a51f8f07770fac2844288d62158 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 16 May 2026 17:02:14 +0200 Subject: [PATCH] Memoize ArrayType->isList() --- src/Type/ArrayType.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Type/ArrayType.php b/src/Type/ArrayType.php index fe8cf48f2bd..b3be6b3b8c9 100644 --- a/src/Type/ArrayType.php +++ b/src/Type/ArrayType.php @@ -57,6 +57,8 @@ class ArrayType implements Type private Type $keyType; + private ?TrinaryLogic $isList = null; + /** @api */ public function __construct(Type $keyType, private Type $itemType) { @@ -262,15 +264,19 @@ public function isConstantArray(): TrinaryLogic public function isList(): TrinaryLogic { - if (IntegerRangeType::fromInterval(0, null)->isSuperTypeOf($this->getKeyType())->no()) { - return TrinaryLogic::createNo(); - } + if ($this->isList === null) { + if (IntegerRangeType::fromInterval(0, null)->isSuperTypeOf($this->getKeyType())->no()) { + return $this->isList = TrinaryLogic::createNo(); + } - if ($this->getKeyType()->isSuperTypeOf(new ConstantIntegerType(0))->no()) { - return TrinaryLogic::createNo(); + if ($this->getKeyType()->isSuperTypeOf(new ConstantIntegerType(0))->no()) { + return $this->isList = TrinaryLogic::createNo(); + } + + return $this->isList = TrinaryLogic::createMaybe(); } - return TrinaryLogic::createMaybe(); + return $this->isList; } public function isConstantValue(): TrinaryLogic