Skip to content

Commit 71e0520

Browse files
committed
Cache scopes
1 parent 68815ac commit 71e0520

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/Analyser/Fiber/FiberScope.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,20 @@ final class FiberScope extends MutatingScope
2020
/** @var Expr[] */
2121
private array $falseyValueExprs = [];
2222

23+
private ?MutatingScope $mutatingScope = null;
24+
2325
public function toFiberScope(): self
2426
{
2527
return $this;
2628
}
2729

2830
public function toMutatingScope(): MutatingScope
2931
{
30-
return $this->scopeFactory->toMutatingFactory()->create(
32+
if ($this->mutatingScope !== null) {
33+
return $this->mutatingScope;
34+
}
35+
36+
return $this->mutatingScope = $this->scopeFactory->toMutatingFactory()->create(
3137
$this->context,
3238
$this->isDeclareStrictTypes(),
3339
$this->getFunction(),

src/Analyser/MutatingScope.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ class MutatingScope implements Scope, NodeCallbackInvoker
186186
/** @var array<string, self> */
187187
private array $falseyScopes = [];
188188

189+
private ?self $fiberScope = null;
190+
189191
/** @var non-empty-string|null */
190192
private ?string $namespace;
191193

@@ -254,7 +256,11 @@ public function toFiberScope(): self
254256
throw new ShouldNotHappenException('Cannot create FiberScope below PHP 8.1');
255257
}
256258

257-
return $this->scopeFactory->toFiberFactory()->create(
259+
if ($this->fiberScope !== null) {
260+
return $this->fiberScope;
261+
}
262+
263+
return $this->fiberScope = $this->scopeFactory->toFiberFactory()->create(
258264
$this->context,
259265
$this->isDeclareStrictTypes(),
260266
$this->getFunction(),

0 commit comments

Comments
 (0)