◐ Shell
clean mode source ↗

GH-104104: Optimize `pathlib.Path.glob()` by avoiding repeated calls to `os.path.normcase()` by barneygale · Pull Request #104105 · python/cpython

Conversation

…calls to `os.path.normcase()`

Use `re.IGNORECASE` to implement case-insensitive matching. This
restores behaviour from before python#31691.

AlexWaygood

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great speedup! LGTM.

What was the motivation for moving to the normcase-based implementation in #31691? Did it just feel simpler at the time?

@barneygale

What was the motivation for moving to the normcase-based implementation in #31691? Did it just feel simpler at the time?

Mostly because os.path doesn't have an attribute indicating whether it's case sensitive or not, and it didn't occur to me at the time to use normcase('Aa') == 'Aa'.

@barneygale

Thanks for the review! :-)

@AlexWaygood

I think you should add an entry to "What's new in 3.12" about all the great optimisation work you've been doing on pathlib. It's a really good improvement that's worth celebrating :)

carljm added a commit to carljm/cpython that referenced this pull request

May 2, 2023

Labels