[Python-3000] Making more effective use of slice objects in Py3k

Josiah Carlson jcarlson at uci.edu
Wed Aug 30 20:25:58 CEST 2006


"Paul Prescod" <paul at prescod.net> wrote:
> Yes, thanks for the clarification. From a type theory point of view there is
> nothing stopping string + view returning a view always (even if it is a view
> of a new string) but that would have very poor performance characteristics.

It depends.  Assume single-segment views (that's what I've been
implementing).  If you have two non-adjacent views, or a view+string
(for non-empty strings), etc., you need to take the time to construct
the new string, that's a given.  But once you have a string, you could
return either the string, or you could return a full view of the string.
The performance differences are fairly insignificant (I was not able to
measure any).

Up until this morning I was planning on writing everything such that
constructive manipulation (upper(), __add__, etc.) returned views of
strings. While I still feel it would be more consistant to always return
views, returning strings does let the user know that "this operation may
take a while" by virtue of returning a string.


 - Josiah



More information about the Python-3000 mailing list