Skip to content

Commit

Permalink
Performance: Memoize sipped file paths (#3495)
Browse files Browse the repository at this point in the history
* Performance: Memoize sipped file paths

* Pin phpunit version
  • Loading branch information
keulinho committed Mar 20, 2023
1 parent ea0c6c1 commit ed11caa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"phpstan/phpstan-php-parser": "^1.1",
"phpstan/phpstan-strict-rules": "^1.4.4",
"phpstan/phpstan-webmozart-assert": "^1.2.2",
"phpunit/phpunit": "^10.0.6",
"phpunit/phpunit": "10.0.16",
"rector/phpstan-rules": "^0.6.5",
"rector/rector-generator": "dev-main",
"spatie/enum": "^3.13",
Expand Down
11 changes: 10 additions & 1 deletion packages/Skipper/SkipVoter/PathSkipVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

final class PathSkipVoter implements SkipVoterInterface
{
/**
* @var array<string, bool>
*/
private array $skippedFiles = [];

public function __construct(
private readonly FileInfoMatcher $fileInfoMatcher,
private readonly SkippedPathsResolver $skippedPathsResolver
Expand All @@ -23,7 +28,11 @@ public function match(string | object $element): bool

public function shouldSkip(string | object $element, string $filePath): bool
{
if (isset($this->skippedFiles[$filePath])) {
return $this->skippedFiles[$filePath];
}

$skippedPaths = $this->skippedPathsResolver->resolve();
return $this->fileInfoMatcher->doesFileInfoMatchPatterns($filePath, $skippedPaths);
return $this->skippedFiles[$filePath] = $this->fileInfoMatcher->doesFileInfoMatchPatterns($filePath, $skippedPaths);
}
}

0 comments on commit ed11caa

Please sign in to comment.