[Python-Dev] String views (was: Re: Proof of the pudding: str.partition())

James Y Knight foom at fuhm.net
Thu Sep 1 04:51:18 CEST 2005


On Aug 31, 2005, at 10:21 PM, skip at pobox.com wrote:

>
>     Tim> One of the big disadvantages of string views is that they  
> need to
>     Tim> keep the original object around, no matter how big it is.  
> But in
>     Tim> the case of partition, much of the time the original string
>     Tim> survives for at least a similar period to the partitions.
>
> Not necessarily.  Presumably a string view would reference another  
> string
> object's data buffer.  A possible optimization would be to convert  
> from a
> view to a normal string once the original strings' refcount dropped  
> to one,
> particularly if the view's size was substantially smaller than that  
> of the
> original string.

I suspect this would be a pessimization most of the time, as it would  
require keeping a list of pointers to all the views referencing the  
string object.

James



More information about the Python-Dev mailing list