mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
GH-114847: Speed up posixpath.realpath()
(#114848)
Apply the following optimizations to `posixpath.realpath()`: - Remove use of recursion - Construct child paths directly rather than using `join()` - Use `os.getcwd[b]()` rather than `abspath()` - Use `startswith(sep)` rather than `isabs()` - Use slicing rather than `split()` Co-authored-by: Petr Viktorin <encukou@gmail.com>
This commit is contained in:
parent
9ceaee74db
commit
abfa16b44b
3 changed files with 64 additions and 34 deletions
|
@ -456,6 +456,15 @@ class PosixPathTest(unittest.TestCase):
|
|||
finally:
|
||||
os_helper.unlink(ABSTFN)
|
||||
|
||||
@os_helper.skip_unless_symlink
|
||||
@skip_if_ABSTFN_contains_backslash
|
||||
def test_realpath_missing_pardir(self):
|
||||
try:
|
||||
os.symlink(os_helper.TESTFN + "1", os_helper.TESTFN)
|
||||
self.assertEqual(realpath("nonexistent/../" + os_helper.TESTFN), ABSTFN + "1")
|
||||
finally:
|
||||
os_helper.unlink(os_helper.TESTFN)
|
||||
|
||||
@os_helper.skip_unless_symlink
|
||||
@skip_if_ABSTFN_contains_backslash
|
||||
def test_realpath_symlink_loops(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue