From 5ecfc427281c90660b84f0294ed21d42c4da3dc6 Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Sun, 10 Feb 2019 19:27:14 +0000 Subject: [PATCH] Early exit if found --- src/Parsing/Lines.php | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/Parsing/Lines.php b/src/Parsing/Lines.php index 2d4a4b4..9e5bd2e 100644 --- a/src/Parsing/Lines.php +++ b/src/Parsing/Lines.php @@ -26,21 +26,18 @@ final class Lines $this->trailingBlankLinesText = $trailingBlankLinesText; $this->trailingBlankLines = \substr_count($trailingBlankLinesText, "\n"); - $this->containsBlankLines = ( - ($this->trailingBlankLines > 0) - || \array_reduce( - $Contexts, - /** - * @param bool $blankFound - * @param Context $Context - * @return bool - */ - function ($blankFound, $Context) { - return $blankFound || ($Context->previousEmptyLines() > 0); - }, - false - ) - ); + $containsBlankLines = $this->trailingBlankLines > 0; + + if (! $containsBlankLines) { + foreach ($Contexts as $Context) { + if ($Context->previousEmptyLines() > 0) { + $containsBlankLines = true; + break; + } + } + } + + $this->containsBlankLines = $containsBlankLines; } /** @return self */