[Patches] [ python-Patches-1007087 ] Return new string for single subclass joins (Bug #1001011)

SourceForge.net noreply at sourceforge.net
Thu Aug 12 00:54:43 CEST 2004


Patches item #1007087, was opened at 2004-08-11 18:03
Message generated for change (Settings changed) made by ncoghlan
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1007087&group_id=5470

Category: Core (C code)
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Nick Coghlan (ncoghlan)
Assigned to: Nobody/Anonymous (nobody)
>Summary: Return new string for single subclass joins (Bug #1001011)

Initial Comment:
At present, str.join contains a shortcut that returns a
reference to the existing string for a sequence that
contains a single item.

This can cause misbehaviour when subclasses of str are
involved (see the bug report for details).

The attached patch removes the shortcut, and adds a
test for the correct behaviour.

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

Comment By: Nick Coghlan (ncoghlan)
Date: 2004-08-12 08:53

Message:
Logged In: YES 
user_id=1038590

Oh - the test looks explicitly for the optimised behaviour
for a true string (to make sure this version preserved that
behaviour). Is that a good idea, or not?

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

Comment By: Nick Coghlan (ncoghlan)
Date: 2004-08-12 08:52

Message:
Logged In: YES 
user_id=1038590

New version of patch attached which uses PyString_CheckExact
and PyUnicode_CheckExact to determine when the optimisation
is safe, and falls through to the general case when it isn't.

Should this optimisation be applied to the unicode join as well?

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

Comment By: Nick Coghlan (ncoghlan)
Date: 2004-08-12 08:17

Message:
Logged In: YES 
user_id=1038590

OK. I think I can do something with PyString_CheckExact that
will do what you'd prefer.

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

Comment By: Tim Peters (tim_one)
Date: 2004-08-11 22:52

Message:
Logged In: YES 
user_id=31435

This is an important optimization for "true strings".  It was 
indeed the intent that internal optimization for immutable 
types not be applied to subclass instances, so it's good to fix 
that.  It's not good to lose the optimization when it's safe.

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

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


More information about the Patches mailing list