From 529d7f193ac8f84640ee80704b73b43edf8572a8 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Wed, 9 Dec 2015 16:12:57 +0100 Subject: [PATCH] Output buffering during buildFrom* functions Improves performance by ~ 20 % if there are a lot of files --- src/lib/Herrera/Box/Box.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib/Herrera/Box/Box.php b/src/lib/Herrera/Box/Box.php index ed0d4d1..dd912a7 100644 --- a/src/lib/Herrera/Box/Box.php +++ b/src/lib/Herrera/Box/Box.php @@ -157,6 +157,8 @@ public function buildFromDirectory($dir, $regex = null) */ public function buildFromIterator(Traversable $iterator, $base = null) { + $this->phar->startBuffering(); + if ($base) { $base = Path::canonical($base . DIRECTORY_SEPARATOR); } @@ -164,6 +166,7 @@ public function buildFromIterator(Traversable $iterator, $base = null) foreach ($iterator as $key => $value) { if (is_string($value)) { if (false === is_string($key)) { + $this->phar->stopBuffering(); throw UnexpectedValueException::create( 'The key returned by the iterator (%s) is not a string.', gettype($key) @@ -180,6 +183,7 @@ public function buildFromIterator(Traversable $iterator, $base = null) } } elseif ($value instanceof SplFileInfo) { if (null === $base) { + $this->phar->stopBuffering(); throw InvalidArgumentException::create( 'The $base argument is required for SplFileInfo values.' ); @@ -189,6 +193,7 @@ public function buildFromIterator(Traversable $iterator, $base = null) $real = $value->getRealPath(); if (0 !== strpos($real, $base)) { + $this->phar->stopBuffering(); throw UnexpectedValueException::create( 'The file "%s" is not in the base directory.', $real @@ -203,12 +208,14 @@ public function buildFromIterator(Traversable $iterator, $base = null) $this->addFile($real, $local); } } else { + $this->phar->stopBuffering(); throw UnexpectedValueException::create( 'The iterator value "%s" was not expected.', gettype($value) ); } } + $this->phar->stopBuffering(); } /**