GH-115060: Speed up pathlib.Path.glob()
by skipping directory scanning
#116152
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For ordinary literal pattern segments (e.g.
foo/bar
infoo/bar/../**
), skip callingscandir()
on each segment, and instead callexists()
oris_dir()
as necessary to exclude missing paths. This only applies when case_sensitive isNone
(the default); otherwise we can't guarantee case sensitivity or realness with this approach. If follow_symlinks isFalse
we also need to exclude symlinks from intermediate segments.This restores an optimization that was removed in da1980a by some eejit. It's actually even faster because we don't
stat()
intermediate directories, and in some cases we can skip all filesystem access when expanding a literal part (e.g. when it's followed by a non-recursive wildcard segment).pathlib.Path.glob()
by removing redundant regex matching #115060