mirror of https://github.com/jab/bidict.git
more efficient OrderedBidirectionalMapping.__eq__ impl
when other is an unordered mapping. Mapping.__eq__() creates a temporary dict (passing self) before comparing and then throws it away. Avoiding that implementation avoids the unnecessary malloc.
This commit is contained in:
parent
d358f82ca3
commit
9c004aa9b4
|
@ -17,7 +17,7 @@ def _make_iter(reverse=False, name='__iter__', doctmpl='Like :meth:`collections.
|
||||||
def _iter(self):
|
def _iter(self):
|
||||||
fwd = self._fwd
|
fwd = self._fwd
|
||||||
end = self._end
|
end = self._end
|
||||||
cur = end[_PRV] if reverse else end[_NXT]
|
cur = end[_PRV if reverse else _NXT]
|
||||||
while cur is not end:
|
while cur is not end:
|
||||||
d, prv, nxt = cur
|
d, prv, nxt = cur
|
||||||
korv = next(iter(d))
|
korv = next(iter(d))
|
||||||
|
@ -182,9 +182,12 @@ class OrderedBidirectionalMapping(BidirectionalMapping):
|
||||||
if i != j:
|
if i != j:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
if isinstance(other, Mapping):
|
if not isinstance(other, Mapping) or len(self) != len(other):
|
||||||
return Mapping.__eq__(self, other)
|
return False
|
||||||
return False
|
for (k, v) in iteritems(other):
|
||||||
|
if self.get(k, _missing) != v:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
inner = ', '.join('(%r, %r)' % (k, v) for (k, v) in iteritems(self))
|
inner = ', '.join('(%r, %r)' % (k, v) for (k, v) in iteritems(self))
|
||||||
|
|
Loading…
Reference in New Issue