Skip to content

Commit 74945e2

Browse files
committed
optimize - use cached file type from DirectoryIterator
1 parent 188d83c commit 74945e2

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/Symfony/Component/Finder/Iterator/ExcludeDirectoryFilterIterator.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,13 @@ public function __construct(\Iterator $iterator, array $directories)
7272
*/
7373
public function accept(): bool
7474
{
75-
if (isset($this->excludedDirs[$this->getFilename()]) && $this->hasChildren()) {
76-
return false;
75+
$hasChildren = null;
76+
if (isset($this->excludedDirs[$this->getFilename()])) {
77+
$hasChildren = $this->hasChildren();
78+
79+
if ($hasChildren) {
80+
return false;
81+
}
7782
}
7883

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

86-
if ($this->isRecursive && $this->isDir()) {
87-
foreach ($this->pruneFilters as $pruneFilter) {
88-
if (!$pruneFilter($this->current())) {
89-
return false;
91+
if ($this->pruneFilters) {
92+
if (null === $hasChildren) {
93+
$hasChildren = $this->hasChildren();
94+
}
95+
96+
if ($hasChildren) {
97+
foreach ($this->pruneFilters as $pruneFilter) {
98+
if (!$pruneFilter($this->current())) {
99+
return false;
100+
}
90101
}
91102
}
92103
}

src/Symfony/Component/Finder/Tests/FinderTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,25 +1068,20 @@ public function testFilterPrune()
10681068
$this->assertSame([
10691069
['x', 'is_dir', true],
10701070
['x', 'list_dir_open', ['a.php', 'b.php', 'd', 'x']],
1071-
['x/a.php', 'is_dir', false], // from ExcludeDirectoryFilterIterator::accept()
1072-
['x/a.php', 'is_dir', false], // from RecursiveDirectoryIterator::hasChildren()
1071+
['x/a.php', 'is_dir', false],
10731072
['x/a.php', 'exclude_filter', true],
10741073
['x/b.php', 'is_dir', false],
1075-
['x/b.php', 'is_dir', false],
10761074
['x/b.php', 'exclude_filter', true],
10771075
['x/d', 'is_dir', true],
10781076
['x/d', 'exclude_filter', false],
10791077
['x/x', 'is_dir', true],
10801078
['x/x', 'exclude_filter', true], // from ExcludeDirectoryFilterIterator::accept() (prune directory filter)
1081-
['x/x', 'is_dir', true],
10821079
['x/x', 'exclude_filter', true], // from CustomFilterIterator::accept() (regular filter)
10831080
['x/x', 'list_dir_open', ['d']],
10841081
['x/x/d', 'is_dir', true],
1085-
['x/x/d', 'is_dir', true],
10861082
['x/x/d', 'exclude_filter', true],
10871083
['x/x/d', 'list_dir_open', ['u2.php']],
10881084
['x/x/d/u2.php', 'is_dir', false],
1089-
['x/x/d/u2.php', 'is_dir', false],
10901085
['x/x/d/u2.php', 'exclude_filter', true],
10911086
], $this->vfsLog);
10921087
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy