From: Zac Medico Date: Mon, 5 May 2008 21:06:30 +0000 (-0000) Subject: Cache results for Task.__hash__() calls. X-Git-Tag: v2.2_pre7~78 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c94e1dd32929829dcd8d05a7040ce95d669957bb;p=portage.git Cache results for Task.__hash__() calls. svn path=/main/trunk/; revision=10210 --- diff --git a/pym/_emerge/__init__.py b/pym/_emerge/__init__.py index 378b4e21d..1baaff7f8 100644 --- a/pym/_emerge/__init__.py +++ b/pym/_emerge/__init__.py @@ -1220,7 +1220,7 @@ def show_masked_packages(masked_packages): return have_eapi_mask class Task(SlotObject): - __slots__ = ("_hash_key",) + __slots__ = ("_hash_key", "_hash_value") def _get_hash_key(self): hash_key = getattr(self, "_hash_key", None) @@ -1235,7 +1235,10 @@ class Task(SlotObject): return self._get_hash_key() != other def __hash__(self): - return hash(self._get_hash_key()) + hash_value = getattr(self, "_hash_value", None) + if hash_value is None: + self._hash_value = hash(self._get_hash_key()) + return self._hash_value def __len__(self): return len(self._get_hash_key())