From: David M. <morley@AI.SRI.COM> - 2009-02-04 11:03:52
|
PyObject._cmp() seems to be doing more work than it needs to. If it get backs "False" rather than NotImplemented/null from a rich comparison method, then it should not need to perform the corresponding reverse operation. So rather than r = __eq__(o); if (r != null && r.__nonzero__()) return 0; r = o.__eq__(this); if (r != null && r.__nonzero__()) return 0; r = __lt__(o); if (r != null && r.__nonzero__()) return -1; r = o.__gt__(this); if (r != null && r.__nonzero__()) return -1; r = __gt__(o); if (r != null && r.__nonzero__()) return 1; r = o.__lt__(this); if (r != null && r.__nonzero__()) return 1; I think it should only need to do r = __eq__(o); if (r == null) r = o.__eq__(this); if (r != null && r.__nonzero__()) return 0; r = __lt__(o); if (r == null) r = o.__gt__(this); if (r != null && r.__nonzero__()) return -1; r = __gt__(o); if (r == null) r = o.__lt__(this); if (r != null && r.__nonzero__()) return 1; For something like a deeply nested sequence comparison, the rich comparison methods might be rather expensive, so eliminating unnecessary calls would be useful. Or am I on the wrong track here? - David |