Skip to content

Commit 4745d6f

Browse files
committed
OutputFormat cache
1 parent fa0fa6d commit 4745d6f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/OutputFormat.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ class OutputFormat
165165
*/
166166
private $iIndentationLevel = 0;
167167

168+
/**
169+
* @var array<string, string|null>
170+
*/
171+
private $varCache = [];
172+
168173
public function __construct()
169174
{
170175
}
@@ -176,10 +181,16 @@ public function __construct()
176181
*/
177182
public function get($sName)
178183
{
184+
if (isset($this->varCache[$sName])) {
185+
return $this->varCache[$sName];
186+
}
187+
179188
$aVarPrefixes = ['a', 's', 'm', 'b', 'f', 'o', 'c', 'i'];
180189
foreach ($aVarPrefixes as $sPrefix) {
181190
$sFieldName = $sPrefix . ucfirst($sName);
182191
if (isset($this->$sFieldName)) {
192+
$this->varCache[$sName] = $this->$sFieldName;
193+
183194
return $this->$sFieldName;
184195
}
185196
}
@@ -211,6 +222,7 @@ public function set($aNames, $mValue)
211222
$sFieldName = $sPrefix . ucfirst($sName);
212223
if (isset($this->$sFieldName)) {
213224
$this->$sFieldName = $mValue;
225+
unset($this->varCache[$sName]);
214226
$bDidReplace = true;
215227
}
216228
}

0 commit comments

Comments
 (0)