Skip to content

Commit

Permalink
Speedup Literal.__hash__ and Literal.__eq__ by accessing directly _da…
Browse files Browse the repository at this point in the history
…tatype and _language.
  • Loading branch information
rchateauneu committed May 18, 2021
1 parent a9aaef1 commit 282a8b7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions rdflib/term.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,10 +969,10 @@ def __hash__(self):
"""
# 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)
if self._language:
res ^= hash(self._language.lower())
if self._datatype:
res ^= hash(self._datatype)
return res

def __eq__(self, other):
Expand Down Expand Up @@ -1017,9 +1017,9 @@ def __eq__(self, other):
return False
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)
)

Expand Down

0 comments on commit 282a8b7

Please sign in to comment.