• Tim Peters's avatar
    Speed tuple comparisons in two ways: · d7ed3bf5
    Tim Peters yazdı
    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.
    d7ed3bf5
tupleobject.c 12.5 KB