Skip to content

Commit e1a76da

Browse files
committed
gh-138407: avoid useless join operation when calculate the hash vaule for pathlib.Path
Signed-off-by: Manjusaka <me@manjusaka.me>
1 parent 097c563 commit e1a76da

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

Lib/pathlib/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,12 @@ def __hash__(self):
209209
try:
210210
return self._hash
211211
except AttributeError:
212-
self._hash = hash(self._str_normcase)
212+
hash_data = self._tail
213+
if self._drv or self._root:
214+
hash_data = [self._drv + self._root] + self._tail
215+
elif self._tail and self.parser.splitdrive(self._tail[0])[0]:
216+
hash_data = ['.'] + self._tail
217+
self._hash = hash(tuple(hash_data))
213218
return self._hash
214219

215220
def __eq__(self, other):

0 commit comments

Comments
 (0)