From e1a76da0a10aef646eb722e64266fd6587f31ae1 Mon Sep 17 00:00:00 2001 From: Manjusaka Date: Mon, 8 Sep 2025 19:03:20 +0800 Subject: [PATCH] gh-138407: avoid useless join operation when calculate the hash vaule for pathlib.Path Signed-off-by: Manjusaka --- Lib/pathlib/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Lib/pathlib/__init__.py b/Lib/pathlib/__init__.py index cea1a9fe57e..5b79b20cb0e 100644 --- a/Lib/pathlib/__init__.py +++ b/Lib/pathlib/__init__.py @@ -209,7 +209,12 @@ def __hash__(self): try: return self._hash except AttributeError: - self._hash = hash(self._str_normcase) + hash_data = self._tail + if self._drv or self._root: + hash_data = [self._drv + self._root] + self._tail + elif self._tail and self.parser.splitdrive(self._tail[0])[0]: + hash_data = ['.'] + self._tail + self._hash = hash(tuple(hash_data)) return self._hash def __eq__(self, other):