Skip to content

Commit

Permalink
This caused bad memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Oct 4, 2021
1 parent c1812e7 commit 25cb765
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 30 deletions.
Expand Up @@ -8,7 +8,7 @@
final class MemoizingClassReflector extends ClassReflector
{

/** @var array<string, \PHPStan\BetterReflection\Reflection\ReflectionClass|\Throwable> */
/** @var array<string, \PHPStan\BetterReflection\Reflection\ReflectionClass> */
private array $reflections = [];

/**
Expand All @@ -22,18 +22,10 @@ public function reflect(string $className): Reflection
{
$lowerClassName = strtolower($className);
if (isset($this->reflections[$lowerClassName])) {
if ($this->reflections[$lowerClassName] instanceof \Throwable) {
throw $this->reflections[$lowerClassName];
}
return $this->reflections[$lowerClassName];
}

try {
return $this->reflections[$lowerClassName] = parent::reflect($className);
} catch (\Throwable $e) {
$this->reflections[$lowerClassName] = $e;
throw $e;
}
return $this->reflections[$lowerClassName] = parent::reflect($className);
}

}
Expand Up @@ -8,7 +8,7 @@
final class MemoizingConstantReflector extends ConstantReflector
{

/** @var array<string, \PHPStan\BetterReflection\Reflection\ReflectionConstant|\Throwable> */
/** @var array<string, \PHPStan\BetterReflection\Reflection\ReflectionConstant> */
private array $reflections = [];

/**
Expand All @@ -21,18 +21,10 @@ final class MemoizingConstantReflector extends ConstantReflector
public function reflect(string $constantName): Reflection
{
if (isset($this->reflections[$constantName])) {
if ($this->reflections[$constantName] instanceof \Throwable) {
throw $this->reflections[$constantName];
}
return $this->reflections[$constantName];
}

try {
return $this->reflections[$constantName] = parent::reflect($constantName);
} catch (\Throwable $e) {
$this->reflections[$constantName] = $e;
throw $e;
}
return $this->reflections[$constantName] = parent::reflect($constantName);
}

}
Expand Up @@ -8,7 +8,7 @@
final class MemoizingFunctionReflector extends FunctionReflector
{

/** @var array<string, \PHPStan\BetterReflection\Reflection\ReflectionFunction|\Throwable> */
/** @var array<string, \PHPStan\BetterReflection\Reflection\ReflectionFunction> */
private array $reflections = [];

/**
Expand All @@ -22,18 +22,10 @@ public function reflect(string $functionName): Reflection
{
$lowerFunctionName = strtolower($functionName);
if (isset($this->reflections[$lowerFunctionName])) {
if ($this->reflections[$lowerFunctionName] instanceof \Throwable) {
throw $this->reflections[$lowerFunctionName];
}
return $this->reflections[$lowerFunctionName];
}

try {
return $this->reflections[$lowerFunctionName] = parent::reflect($functionName);
} catch (\Throwable $e) {
$this->reflections[$lowerFunctionName] = $e;
throw $e;
}
return $this->reflections[$lowerFunctionName] = parent::reflect($functionName);
}

}

0 comments on commit 25cb765

Please sign in to comment.