diff --git a/rdflib/term.py b/rdflib/term.py index 0f627e69f..36f84aaa2 100644 --- a/rdflib/term.py +++ b/rdflib/term.py @@ -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): @@ -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) )