[Python-bugs-list] [ python-Bugs-420490 ] lookdict_string does not use interning

noreply@sourceforge.net noreply@sourceforge.net
Wed, 09 May 2001 19:26:20 -0700


Bugs item #420490, was updated on 2001-05-01 10:06
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=420490&group_id=5470

Category: Python Interpreter Core
>Group: Not a Bug
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Greg Chapman (glchapman)
Assigned to: Tim Peters (tim_one)
Summary: lookdict_string does not use interning

Initial Comment:
In Python 2.1, when a dictionary uses lookdict_string 
to retrieve items, the function used to compare 
strings is PyString_Type.tp_compare, i.e. 
string_compare.  string_compare does not check if its 
parameters are actually the same PStringObject *, so 
an actual string comparison is made even if the 
dictionary's keys have been interned.  Python 1.52 
used PyObject_Compare to compare all keys, and this 
function did check to see if its parameters were the 
same PyObject *.

I wonder if this might be one source of the slow-down 
in Python 2.1?


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

>Comment By: Tim Peters (tim_one)
Date: 2001-05-09 19:26

Message:
Logged In: YES 
user_id=31435

Closed as requested.  Cheer up, though!  You're certainly 
not the first one to miss this trick.  The dict code is 
subtle to the point of looking straightforward <wink>.


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

Comment By: Greg Chapman (glchapman)
Date: 2001-05-01 10:20

Message:
Logged In: YES 
user_id=86307

Actually, I apologize for wasting everyone's time.  This 
report is totally false; I missed this line:

	if (ep->me_key == NULL || ep->me_key == key)
		return ep;

Please ignore this.  I'm going to go get some sleep.



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

Comment By: Greg Chapman (glchapman)
Date: 2001-05-01 10:17

Message:
Logged In: YES 
user_id=86307

Actually, to be more specific, only the first comparison in 
lookdict_string forgets to see if the string pointers are 
the same.  I assume the proper fix would be to change this 
first comparison to be:

 	if (ep->me_key == dummy)
 		freeslot = ep;
 	else {
-		if (ep->me_hash == hash
-		    && compare(ep->me_key, key) == 0) {
+		if (ep->me_key == key
+                    || (ep->me_hash == hash
+		    && compare(ep->me_key, key) == 0)) {
 			return ep;
 		}
 		freeslot = NULL;
 	}


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

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