From 8d09320009b0a9adee63ef358dfb4481ebb90dab Mon Sep 17 00:00:00 2001 From: Aidan Woods Date: Sun, 19 Jan 2020 15:31:33 +0000 Subject: [PATCH] Compute on read optimisation for previousEmptyLines --- src/Parsing/Context.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Parsing/Context.php b/src/Parsing/Context.php index a100327..b8a02e2 100644 --- a/src/Parsing/Context.php +++ b/src/Parsing/Context.php @@ -7,7 +7,7 @@ final class Context /** @var Line */ private $Line; - /** @var int */ + /** @var int|null */ private $previousEmptyLines; /** @var string */ @@ -21,7 +21,7 @@ final class Context { $this->Line = $Line; $this->previousEmptyLinesText = $previousEmptyLinesText; - $this->previousEmptyLines = \substr_count($previousEmptyLinesText, "\n"); + $this->previousEmptyLines = null; } /** @return Line */ @@ -33,6 +33,10 @@ final class Context /** @return int */ public function previousEmptyLines() { + if (! isset($this->previousEmptyLines)) { + $this->previousEmptyLines = \substr_count($this->previousEmptyLinesText, "\n"); + } + return $this->previousEmptyLines; }