From 40d0e5763f2a7d85bebc8acb8c4facb7413d030a Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Tue, 8 Oct 2024 23:21:58 +0200 Subject: [PATCH 1/3] Speed up `posixpath.realpath()` in the common case --- Lib/posixpath.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Lib/posixpath.py b/Lib/posixpath.py index fccca4e066b76f..89d8267d927c65 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -428,13 +428,14 @@ def _realpath(filename, strict=False, sep=sep, curdir=curdir, pardir=pardir, while rest: name = rest.pop() - if name is None: - # resolved symlink target - seen[rest.pop()] = path - continue if not name or name == curdir: - # current dir - continue + if name is None: + # resolved symlink target + seen[rest.pop()] = path + continue + else: + # current dir + continue if name == pardir: # parent dir path = path[:path.rindex(sep)] or sep From 0fe02d9cec85ff174f3f951e5298aa4170a4547f Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 8 Oct 2024 21:29:32 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2024-10-08-21-29-30.gh-issue-125159.jmi9FB.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2024-10-08-21-29-30.gh-issue-125159.jmi9FB.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-10-08-21-29-30.gh-issue-125159.jmi9FB.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-10-08-21-29-30.gh-issue-125159.jmi9FB.rst new file mode 100644 index 00000000000000..d316544cfc395b --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-10-08-21-29-30.gh-issue-125159.jmi9FB.rst @@ -0,0 +1 @@ +Speed up :func:`os.path.realpath` on Unix. From ff6394982f671f68fee5596f3e9be7d8b23ae660 Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Wed, 9 Oct 2024 07:49:15 +0200 Subject: [PATCH 3/3] Update Lib/posixpath.py Co-authored-by: Barney Gale --- Lib/posixpath.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Lib/posixpath.py b/Lib/posixpath.py index 89d8267d927c65..565ffd136c55ce 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -429,13 +429,11 @@ def _realpath(filename, strict=False, sep=sep, curdir=curdir, pardir=pardir, while rest: name = rest.pop() if not name or name == curdir: + # current dir if name is None: # resolved symlink target seen[rest.pop()] = path - continue - else: - # current dir - continue + continue if name == pardir: # parent dir path = path[:path.rindex(sep)] or sep