Visitar URL original
Micro-optimize pathlib path parsing and joining · Issue #113373 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20260616032558/https://github.com/python/cpython/issues/113373
Skip to content
/ cpython Public

Micro-optimize pathlib path parsing and joining #113373

@barneygale

Description

@barneygale

There are a few small adjustments we can make to pathlib path initialization and joining that improve performance:

  1. Ignore empty strings given to the initializer, which saves a pathmod.join() call
  2. Store joined string in self._raw_paths, which makes subsequent joining faster
  3. Handle empty paths without calling _parse_path()
  4. Check for the common case (len(self._raw_paths) == 1) first, and replace a length check with a truth check in the subsequent elif:
  5. Remove some unneeded local variables.

Linked PRs

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions