Skip to content

Commit

Permalink
optimize - use cached file type from DirectoryIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jul 12, 2023
1 parent 188d83c commit 74945e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ public function __construct(\Iterator $iterator, array $directories)
*/
public function accept(): bool
{
if (isset($this->excludedDirs[$this->getFilename()]) && $this->hasChildren()) {
return false;
$hasChildren = null;
if (isset($this->excludedDirs[$this->getFilename()])) {
$hasChildren = $this->hasChildren();

if ($hasChildren) {
return false;
}
}

if ($this->excludedPattern) {
Expand All @@ -83,10 +88,16 @@ public function accept(): bool
return !preg_match($this->excludedPattern, $path);
}

if ($this->isRecursive && $this->isDir()) {
foreach ($this->pruneFilters as $pruneFilter) {
if (!$pruneFilter($this->current())) {
return false;
if ($this->pruneFilters) {
if (null === $hasChildren) {
$hasChildren = $this->hasChildren();
}

if ($hasChildren) {
foreach ($this->pruneFilters as $pruneFilter) {
if (!$pruneFilter($this->current())) {
return false;
}
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/Symfony/Component/Finder/Tests/FinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1068,25 +1068,20 @@ public function testFilterPrune()
$this->assertSame([
['x', 'is_dir', true],
['x', 'list_dir_open', ['a.php', 'b.php', 'd', 'x']],
['x/a.php', 'is_dir', false], // from ExcludeDirectoryFilterIterator::accept()
['x/a.php', 'is_dir', false], // from RecursiveDirectoryIterator::hasChildren()
['x/a.php', 'is_dir', false],
['x/a.php', 'exclude_filter', true],
['x/b.php', 'is_dir', false],
['x/b.php', 'is_dir', false],
['x/b.php', 'exclude_filter', true],
['x/d', 'is_dir', true],
['x/d', 'exclude_filter', false],
['x/x', 'is_dir', true],
['x/x', 'exclude_filter', true], // from ExcludeDirectoryFilterIterator::accept() (prune directory filter)
['x/x', 'is_dir', true],
['x/x', 'exclude_filter', true], // from CustomFilterIterator::accept() (regular filter)
['x/x', 'list_dir_open', ['d']],
['x/x/d', 'is_dir', true],
['x/x/d', 'is_dir', true],
['x/x/d', 'exclude_filter', true],
['x/x/d', 'list_dir_open', ['u2.php']],
['x/x/d/u2.php', 'is_dir', false],
['x/x/d/u2.php', 'is_dir', false],
['x/x/d/u2.php', 'exclude_filter', true],
], $this->vfsLog);
}
Expand Down

0 comments on commit 74945e2

Please sign in to comment.