-
-
Notifications
You must be signed in to change notification settings - Fork 702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft: Generalize dirEntries to take a DirEntry predicate as parameter #8586
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs documentation
902a4c5
to
62b9c0c
Compare
I don't think you need to worry about breakage when moving that to last position of the parameter list. The documentation says "set automatically - do not touch", it asserts null if set against what the compiler switch says, and it has existed for only a short while. |
Great. Will adjust then. |
Needs tests. |
Thanks for your pull request and interest in making D better, @nordlow! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#8586" |
Lots of seemingly unrelated CI errors... |
The predicate should not be a template parameter. It increases symbol count, and prevents configurability at runtime. |
@nordlow if you could add some documentation and a chengelog entry to this we can definitely merge this |
Great. What shall the default value of the predicate be? The one that I provided with DirEntry passed as ref or simply pred = void? |
If null, old behavior. If non-null call it. |
I believe it's more common we can use Alternatively
could be used. |
All of which are related to template parameters. My comment was about converting it to a function parameter. |
Ahh. I see. |
Are we ok with using bool delegate(scope ref DirEntry entry) pred; as a run-time parameter and store this in private struct DirIteratorImpl
{
bool delegate(scope ref DirEntry entry) pred;
this(bool delegate(scope ref DirEntry entry) pred)
{
this.pred = pred;
}
.... be used? |
It would need to be |
The current state of
dirEntries
is not generic enough because it cannot traverse any directory treeX
(viaSpanMode.depth
) without having to traverse all sub-directories ofX
such as .git directory trees.Adding a template parameter
to
dirEntries
alleviates this problem.No tests yet and no template restriction enabled yet because I'm uncertain if we should require the pred to take the DirEntry by ref or not given that
DirEntry.sizeof
is 156.Moreover, it's unfortunate that the template parameter
useDIP1000
was recently added toas I presume that
pred
is gonna be a much more common non-default template parameter than then useDIP1000 is gonna be.Shall we add a new function say
treeEntries
,dirTreeEntries
,dirEntriesTree
ordirEntriesFiltered
or whatever instead so we can makepred
the first template parameter?Note that
DirEntry
memberis non-const on posix so that pred cannot be
in the general case. Will add documentation and tests when we have settled on solutions to these issues.
For the corresponding filtering in Rust see https://crates.io/crates/walkdir section "Example: skip hidden files and directories efficiently on unix".