[Patches] [ python-Patches-424475 ] Speed-up tp_compare usage

noreply@sourceforge.net noreply@sourceforge.net
Wed, 15 Aug 2001 13:51:31 -0700


Patches item #424475, was opened at 2001-05-16 01:07
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=424475&group_id=5470

Category: core (C code)
Group: None
>Status: Open
Resolution: Accepted
>Priority: 7
Submitted By: Martin v. Löwis (loewis)
Assigned to: Nobody/Anonymous (nobody)
Summary: Speed-up tp_compare usage

Initial Comment:
This patch tries to optimize PyObject_RichCompare for
the common case of objects with equal types which
support tp_compare. It gives a speed-up of roughly 7%
for comparing strings in a loop.

The patch also gives type objects a tp_compare
function, so that they can make use of the improvement.

----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-08-15 13:51

Message:
Logged In: YES 
user_id=6380

I have to reopen this, because I've encountered a bug (I
think).
Take a trivial class:
  class C: pass
and compare two instances of it:
  cmp(C(), C())
In Python 2.1.1 and before, this returned the same as
  cmp(id(C()), id(C()))
but currently it always returns the value 2!

This 2 is supposed to be an internal value that should never
be returned.

I am not 100% sure that it is this patch that's at fault,
but I selectively
rolled the object.c part of this patch back, and then it
started doing the
right thing again.

I'm going to check in a test that verifies the correct
behavior.

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2001-06-09 00:40

Message:
Logged In: YES 
user_id=21627

Committed as object.c 2.132, typeobject.c 2.17, 
UserList.py 1.17.


----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2001-06-07 13:19

Message:
Logged In: YES 
user_id=31435

Accepted and assigned back to Martin.  This is too valuable 
to quibble over.  Note that when calling a tp_compare slot, 
this kind of thing:

.	c = (*f)(v, w);
.	if (PyErr_Occurred())

is better spelled:

.	c = (*f)(v, w);
.	if (c < 0 && Py_Err_Occurred())


----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2001-05-21 09:57

Message:
Logged In: YES 
user_id=21627

The revised patch prefers tp_compare over tp_richcompare in
do_cmp if both are available. It also restores
UserList.__cmp__ from deprecation.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=424475&group_id=5470