Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speedup Literal.__hash__ and Literal.__eq__ by accessing directly _da… #1321

Merged
merged 2 commits into from
Jun 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions rdflib/term.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,10 +969,11 @@ 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)
# 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):
Expand Down Expand Up @@ -1015,11 +1016,12 @@ def __eq__(self, other):
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)
)

Expand Down