Icinga\Protocol\File\FileReader::count(): call iterator_count() only once per instance and cache the returned value
This commit is contained in:
parent
5ba539b7c1
commit
3d53e6f9b5
|
@ -26,6 +26,13 @@ class FileReader implements Selectable, Countable
|
|||
*/
|
||||
protected $filename;
|
||||
|
||||
/**
|
||||
* Cache for static::count()
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $count = null;
|
||||
|
||||
/**
|
||||
* Create a new reader
|
||||
*
|
||||
|
@ -71,7 +78,10 @@ class FileReader implements Selectable, Countable
|
|||
*/
|
||||
public function count()
|
||||
{
|
||||
return iterator_count($this->iterate());
|
||||
if ($this->count === null) {
|
||||
$this->count = iterator_count($this->iterate());
|
||||
}
|
||||
return $this->count;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue