GH-112361: Speed up pathlib by removing some temporary objects. (#112362)

Construct only one new list object (using `list.copy()`) when creating a
new path object with a modified tail. This slightly speeds up
`with_name()` and `with_suffix()`
This commit is contained in:
Barney Gale 2023-11-25 17:19:38 +00:00 committed by GitHub
parent 6b961b8cea
commit 19a1fc1b3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 22 deletions

View file

@ -575,8 +575,6 @@ class PurePathTest(unittest.TestCase):
self.assertRaises(ValueError, P('a/b').with_suffix, '.c/.d')
self.assertRaises(ValueError, P('a/b').with_suffix, './.d')
self.assertRaises(ValueError, P('a/b').with_suffix, '.d/.')
self.assertRaises(ValueError, P('a/b').with_suffix,
(self.pathmod.sep, 'd'))
def test_relative_to_common(self):
P = self.cls