Content-Length: 282722 | pFad | https://github.com/python/cpython/issues/113225

57 Optimize `pathlib.Path.iterdir()` and friends by using `os.DirEntry.path` · Issue #113225 · python/cpython · GitHub
Skip to content

Optimize pathlib.Path.iterdir() and friends by using os.DirEntry.path #113225

@barneygale

Description

@barneygale

pathlib.Path.glob() calls os.scandir() under the hood, converting os.DirEntry objects to path objects using a private _make_child_relpath() method. This builds a child path from a given basename. The basename is obtained from the dir entry's name attribute.

I've just spotted (or realised) that dir entries have a path attribute that we could use, rather than constructing our own string path from the basename. This seems to be a fair bit faster in my testing.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









      ApplySandwichStrip

      pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


      --- a PPN by Garber Painting Akron. With Image Size Reduction included!

      Fetched URL: https://github.com/python/cpython/issues/113225

      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy