◐ Shell
clean mode source ↗

Speed up pathlib by removing a few temporary objects

A handful of pathlib methods that create paths with modified names, or additional segments, use list objects that are quickly thrown away. We can speed these methods up by only creating new lists where strictly necessary.

Specifically:

  • with_name() (performance of self._tail[:-1] + [name] is cursed)
  • with_suffix()
  • _make_child_relpath() (used in glob() and walk())
  • glob() (when parsing the pattern)

Linked PRs