aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-03-14 00:32:30 +0900
committernsfisis <nsfisis@gmail.com>2024-03-14 00:32:30 +0900
commit9bf23e2abf74d70b77726a4300917c78bc8035e7 (patch)
treea4d4695b334e1cdb9864787766598f2900600e49 /src
parentf490780439450a06cf71eb40b453fc0154264337 (diff)
downloadphp-waddiwasi-9bf23e2abf74d70b77726a4300917c78bc8035e7.tar.gz
php-waddiwasi-9bf23e2abf74d70b77726a4300917c78bc8035e7.tar.zst
php-waddiwasi-9bf23e2abf74d70b77726a4300917c78bc8035e7.zip
perf: cache current frame
Diffstat (limited to 'src')
-rw-r--r--src/Execution/Stack.php17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/Execution/Stack.php b/src/Execution/Stack.php
index 396cb29..a96a875 100644
--- a/src/Execution/Stack.php
+++ b/src/Execution/Stack.php
@@ -13,6 +13,8 @@ final class Stack
*/
private array $frames = [];
+ private ?Frame $currentFrame = null;
+
/**
* @param list<int|float|Ref|Frame|Label> $entries
*/
@@ -25,6 +27,7 @@ final class Stack
{
$this->push($frame);
$this->frames[] = $frame;
+ $this->currentFrame = $frame;
}
public function pushLabel(Label $label): void
@@ -62,6 +65,11 @@ final class Stack
$result = $this->pop();
assert($result instanceof Frame);
array_pop($this->frames);
+ if (count($this->frames) === 0) {
+ $this->currentFrame = null;
+ } else {
+ $this->currentFrame = end($this->frames);
+ }
return $result;
}
@@ -137,6 +145,11 @@ final class Stack
}
}
array_pop($this->frames);
+ if (count($this->frames) === 0) {
+ $this->currentFrame = null;
+ } else {
+ $this->currentFrame = end($this->frames);
+ }
}
public function top(): int|float|Ref|Frame|Label|null
@@ -157,8 +170,8 @@ final class Stack
public function currentFrame(): Frame
{
- assert(count($this->frames) !== 0);
- return $this->frames[count($this->frames) - 1];
+ assert($this->currentFrame !== null);
+ return $this->currentFrame;
}
private function push(int|float|Ref|Frame|Label $entry): void