Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b5dd592

Browse filesBrowse files
committed
optimize - use cached file type from DirectoryIterator
1 parent ba898df commit b5dd592
Copy full SHA for b5dd592

File tree

Expand file treeCollapse file tree

2 files changed

+18
-12
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-12
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Finder/Iterator/ExcludeDirectoryFilterIterator.php
+17-6Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Finder/Tests/FinderTest.php
+1-6Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.