Skip to content

Commit

Permalink
Icinga\Protocol\File\FileReader::count(): call iterator_count() only …
Browse files Browse the repository at this point in the history
…once per instance and cache the returned value
  • Loading branch information
Al2Klimov committed Apr 24, 2015
1 parent 5ba539b commit 3d53e6f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion library/Icinga/Protocol/File/FileReader.php
Expand Up @@ -26,6 +26,13 @@ class FileReader implements Selectable, Countable
*/
protected $filename;

/**
* Cache for static::count()
*
* @var int
*/
protected $count = null;

/**
* Create a new reader
*
Expand Down Expand Up @@ -71,7 +78,10 @@ public function select()
*/
public function count()
{
return iterator_count($this->iterate());
if ($this->count === null) {
$this->count = iterator_count($this->iterate());
}
return $this->count;
}

/**
Expand Down

0 comments on commit 3d53e6f

Please sign in to comment.