[Python-Dev] Comparison speed

Tim Peters tim.one@home.com
Sun, 20 May 2001 06:13:14 -0400


[Guido]
> I have always thought that eventually (but long before Py3K!) all
> objects would only support rich comparisons and the __cmp__ and
> tp_compare slots would become completely obsolete.

If the time machine batteries can hold a full charge, you may want to go back
and add Py_CMP as a seventh possible desired-operation argument to tbe rich
comparison API.  My experience with dict comparisons was that
dict_richcompare couldn't compute Py_LT/LE/GT/GE any cheaper than by doing a
full cmp, so I put the dict oldcmp back in order to avoid having dict richcmp
(potentially) compute cmp 3 times to fake one cmp.  But if dict richcmp knew
a cmp outcome was desired, it could compute it with no extra work to speak
of.  Then there would be no reason at all to hold on to the dict tp_compare
slot.

The list and tuple richcmps are also doing almost all the work needed to
compute a 3-way cmp outcome.