Skip to content

Commit

Permalink
Merge pull request #1561 from markotoplak/domainhash
Browse files Browse the repository at this point in the history
Avoid frequent recomputation of domain hashes.
  • Loading branch information
astaric authored Sep 16, 2016
2 parents 79881fa + e2df3f7 commit 6d039f1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Orange/data/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ def __init__(self, attributes, class_vars=None, metas=None, source=None):
self._known_domains = weakref.WeakKeyDictionary()
self._last_conversion = None

# Precompute hash, which is frequently used in domain conversions.
self._hash = hash(self.attributes) ^ hash(self.class_vars) ^ hash(self.metas)

# noinspection PyPep8Naming
@classmethod
def from_numpy(cls, X, Y=None, metas=None):
Expand Down Expand Up @@ -422,4 +425,4 @@ def __eq__(self, other):
self.metas == other.metas)

def __hash__(self):
return hash(self.attributes) ^ hash(self.class_vars) ^ hash(self.metas)
return self._hash

0 comments on commit 6d039f1

Please sign in to comment.