Skip to content

Commit 5ffeef9

Browse files
committed
Memoize ArrayType->isList()
1 parent 9abd515 commit 5ffeef9

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
@@ -57,6 +57,8 @@ class ArrayType implements Type
5757

5858
private Type $keyType;
5959

60+
private ?TrinaryLogic $isList = null;
61+
6062
/** @api */
6163
public function __construct(Type $keyType, private Type $itemType)
6264
{
@@ -262,15 +264,19 @@ public function isConstantArray(): TrinaryLogic
262264

263265
public function isList(): TrinaryLogic
264266
{
265-
if (IntegerRangeType::fromInterval(0, null)->isSuperTypeOf($this->getKeyType())->no()) {
266-
return TrinaryLogic::createNo();
267-
}
267+
if ($this->isList === null) {
268+
if (IntegerRangeType::fromInterval(0, null)->isSuperTypeOf($this->getKeyType())->no()) {
269+
return $this->isList = TrinaryLogic::createNo();
270+
}
268271

269-
if ($this->getKeyType()->isSuperTypeOf(new ConstantIntegerType(0))->no()) {
270-
return TrinaryLogic::createNo();
272+
if ($this->getKeyType()->isSuperTypeOf(new ConstantIntegerType(0))->no()) {
273+
return $this->isList = TrinaryLogic::createNo();
274+
}
275+
276+
return $this->isList = TrinaryLogic::createMaybe();
271277
}
272278

273-
return TrinaryLogic::createMaybe();
279+
return $this->isList;
274280
}
275281

276282
public function isConstantValue(): TrinaryLogic

0 commit comments

Comments
 (0)