mirror of https://github.com/python/cpython
GH-79634: Speed up pathlib globbing by removing `joinpath()` call. (#114623)
Remove `self.joinpath('')` call that should have been removed in 6313cdde
.
This makes `PathBase.glob('')` yield itself *without* adding a trailing slash. It's hard to say whether this is more or less correct, but at least everything else is faster, and there's no behaviour change in the public classes where empty glob patterns are disallowed.
This commit is contained in:
parent
7a470541e2
commit
823a38a960
|
@ -771,7 +771,7 @@ class PathBase(PurePathBase):
|
||||||
filter_paths = False
|
filter_paths = False
|
||||||
deduplicate_paths = False
|
deduplicate_paths = False
|
||||||
sep = self.pathmod.sep
|
sep = self.pathmod.sep
|
||||||
paths = iter([self.joinpath('')] if self.is_dir() else [])
|
paths = iter([self] if self.is_dir() else [])
|
||||||
while stack:
|
while stack:
|
||||||
part = stack.pop()
|
part = stack.pop()
|
||||||
if part in specials:
|
if part in specials:
|
||||||
|
|
|
@ -1232,6 +1232,8 @@ class PathTest(test_pathlib_abc.DummyPathTest, PurePathTest):
|
||||||
list(p.glob(''))
|
list(p.glob(''))
|
||||||
with self.assertRaisesRegex(ValueError, 'Unacceptable pattern'):
|
with self.assertRaisesRegex(ValueError, 'Unacceptable pattern'):
|
||||||
list(p.glob('.'))
|
list(p.glob('.'))
|
||||||
|
with self.assertRaisesRegex(ValueError, 'Unacceptable pattern'):
|
||||||
|
list(p.glob('./'))
|
||||||
|
|
||||||
def test_glob_many_open_files(self):
|
def test_glob_many_open_files(self):
|
||||||
depth = 30
|
depth = 30
|
||||||
|
|
|
@ -1733,12 +1733,11 @@ class DummyPathTest(DummyPurePathTest):
|
||||||
self.assertEqual(set(map(str, p.glob("F*a"))), {f"{p}\\fileA"})
|
self.assertEqual(set(map(str, p.glob("F*a"))), {f"{p}\\fileA"})
|
||||||
|
|
||||||
def test_glob_empty_pattern(self):
|
def test_glob_empty_pattern(self):
|
||||||
def _check(glob, expected):
|
|
||||||
self.assertEqual(set(glob), { P(self.base, q) for q in expected })
|
|
||||||
P = self.cls
|
P = self.cls
|
||||||
p = P(self.base)
|
p = P(self.base)
|
||||||
_check(p.glob(""), [""])
|
self.assertEqual(list(p.glob("")), [p])
|
||||||
_check(p.glob("."), ["."])
|
self.assertEqual(list(p.glob(".")), [p / "."])
|
||||||
|
self.assertEqual(list(p.glob("./")), [p / "./"])
|
||||||
|
|
||||||
def test_glob_case_sensitive(self):
|
def test_glob_case_sensitive(self):
|
||||||
P = self.cls
|
P = self.cls
|
||||||
|
|
Loading…
Reference in New Issue