Skip to content

Commit e6ed7c4

Browse files
committed
Memoize ArrayType->isList() (#5680)
1 parent 0d01465 commit e6ed7c4

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

src/Type/ArrayType.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class ArrayType implements Type
6161
private Type $keyType;
6262

6363
private ?Type $cachedIterableKeyType = null;
64+
65+
private ?TrinaryLogic $isList = null;
6466

6567
/** @api */
6668
public function __construct(Type $keyType, private Type $itemType)
@@ -296,15 +298,19 @@ public function isConstantArray(): TrinaryLogic
296298

297299
public function isList(): TrinaryLogic
298300
{
299-
if (IntegerRangeType::fromInterval(0, null)->isSuperTypeOf($this->getKeyType())->no()) {
300-
return TrinaryLogic::createNo();
301-
}
301+
if ($this->isList === null) {
302+
if (IntegerRangeType::fromInterval(0, null)->isSuperTypeOf($this->getKeyType())->no()) {
303+
return $this->isList = TrinaryLogic::createNo();
304+
}
302305

303-
if ($this->getKeyType()->isSuperTypeOf(new ConstantIntegerType(0))->no()) {
304-
return TrinaryLogic::createNo();
306+
if ($this->getKeyType()->isSuperTypeOf(new ConstantIntegerType(0))->no()) {
307+
return $this->isList = TrinaryLogic::createNo();
308+
}
309+
310+
return $this->isList = TrinaryLogic::createMaybe();
305311
}
306312

307-
return TrinaryLogic::createMaybe();
313+
return $this->isList;
308314
}
309315

310316
public function isConstantValue(): TrinaryLogic

0 commit comments

Comments
 (0)