Skip to content

Commit

Permalink
Do not cache count result
Browse files Browse the repository at this point in the history
  • Loading branch information
jrabausch committed May 31, 2022
1 parent 9379aed commit c8abc1f
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ class Result implements OuterIterator, Countable
/** @var Iterator */
protected $iterator;

/** @var null|int */
protected $count;

public function __construct(Criteria $criteria, Iterator $iterator)
{
$this->iterator = $iterator;
$this->criteria = $criteria;
$this->iterator = $iterator;
}

public function getInnerIterator(): Iterator
Expand All @@ -51,19 +48,11 @@ public function first()

public function count(): int
{
if ($this->count !== null) {
return $this->count;
}

$this->count = 0;

if ($this->iterator instanceof Countable) {
$this->count = count($this->iterator);
} else {
$this->count = iterator_count($this->iterator);
return count($this->iterator);
}

return $this->count;
return iterator_count($this->iterator);
}

public function empty(): bool
Expand Down

0 comments on commit c8abc1f

Please sign in to comment.