mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-24 22:34:24 +02:00
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;
|
protected $filename;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache for static::count()
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $count = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new reader
|
* Create a new reader
|
||||||
*
|
*
|
||||||
@ -71,7 +78,10 @@ class FileReader implements Selectable, Countable
|
|||||||
*/
|
*/
|
||||||
public function count()
|
public function count()
|
||||||
{
|
{
|
||||||
return iterator_count($this->iterate());
|
if ($this->count === null) {
|
||||||
|
$this->count = iterator_count($this->iterate());
|
||||||
|
}
|
||||||
|
return $this->count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user