Icinga\Protocol\File\FileReader::count(): call iterator_count() only once per instance and cache the returned value

This commit is contained in:
Alexander A. Klimov 2015-04-24 11:10:40 +02:00
parent 5ba539b7c1
commit 3d53e6f9b5
1 changed files with 11 additions and 1 deletions

View File

@ -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;
}
/**