]> granicus.if.org Git - python/commit
Speed tuple comparisons in two ways:
authorTim Peters <tim.peters@gmail.com>
Tue, 15 May 2001 20:12:59 +0000 (20:12 +0000)
committerTim Peters <tim.peters@gmail.com>
Tue, 15 May 2001 20:12:59 +0000 (20:12 +0000)
commitd7ed3bf5524f68860536e330e2a5b1cc50c10f77
tree18735acd5afb38a5435cca47bf764fbe2b50b4cc
parentfab96cc2ffd2834a0c2e6c10f5649740e87b6214
Speed tuple comparisons in two ways:
1. Omit the early-out EQ/NE "lengths different?" test.  Was unable to find
   any real code where it triggered, but it always costs.  The same is not
   true of list richcmps, where different-size lists appeared to get
   compared about half the time.
2. Because tuples are immutable, there's no need to refetch the lengths of
   both tuples from memory again on each loop trip.

BUG ALERT:  The tuple (and list) richcmp algorithm is arguably wrong,
because it won't believe there's any difference unless Py_EQ returns false
for some corresponding elements:

>>> class C:
...     def __lt__(x, y): return 1
...     __eq__ = __lt__
...
>>> C() < C()
1
>>> (C(),) < (C(),)
0
>>>

That doesn't make sense -- provided you believe the defn. of C makes sense.
Objects/tupleobject.c