diff options
author | Nicholas Car <nicholas.car@surroundaustralia.com> | 2021-06-30 09:50:15 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-30 09:50:15 +1000 |
commit | e4d975af6ee4e38b6bb7473b5660c84f787b5d94 (patch) | |
tree | 3e69ab9c4b07dfdf983d56401076c3c972f710ec | |
parent | 871f79701f4ccf90c3ffa94cf3c75b3a973fca2f (diff) | |
parent | 42c90d97f8564e7676023a59b860c05997870eaf (diff) | |
download | rdflib-e4d975af6ee4e38b6bb7473b5660c84f787b5d94.tar.gz |
Merge pull request #1321 from rchateauneu/speedup_term_hash
Speedup Literal.__hash__ and Literal.__eq__ by accessing directly _da…
-rw-r--r-- | rdflib/term.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/rdflib/term.py b/rdflib/term.py index 8a973e1c..0a877daa 100644 --- a/rdflib/term.py +++ b/rdflib/term.py @@ -978,10 +978,11 @@ class Literal(Identifier): """ # don't use super()... for efficiency reasons, see Identifier.__hash__ res = str.__hash__(self) - if self.language: - res ^= hash(self.language.lower()) - if self.datatype: - res ^= hash(self.datatype) + # Directly accessing the member is faster than the property. + if self._language: + res ^= hash(self._language.lower()) + if self._datatype: + res ^= hash(self._datatype) return res def __eq__(self, other): @@ -1024,11 +1025,12 @@ class Literal(Identifier): return True if other is None: return False + # Directly accessing the member is faster than the property. if isinstance(other, Literal): return ( - self.datatype == other.datatype - and (self.language.lower() if self.language else None) - == (other.language.lower() if other.language else None) + self._datatype == other._datatype + and (self._language.lower() if self._language else None) + == (other._language.lower() if other._language else None) and str.__eq__(self, other) ) |