olson-sean-k / wax

Opinionated and portable globs that can be matched against paths and directory trees.
https://glob.guide
MIT License
112 stars 10 forks source link

Optimize based on how predicted maximum depth #35

Closed Dorumin closed 8 months ago

Dorumin commented 1 year ago

Globs can sometimes know how deep they will have to traverse. * will never have to go deeper than one level, and */*/* will never have to go deeper than three.

You can't predict how deep a tree wildcard ** can go, so you have to bail out on any heuristic that encounters it. Same goes for repetitions.

Such a heuristic could probably make a definite prediction on maximum depth for patterns that don't include any of these, but the important thing would to never underestimate how many segments a pattern may match. So it would probably be smart to only apply it when the user hasn't provided a WalkBehavior.depth. Unfortunately, it's not an Option, so maybe you'd have to compare it to usize::MAX, or change WalkBehavior and introduce a breaking change.

Is this a reasonable thing to expect from the library? I would like for it to be in this library and not in, say, nym, if implemented.