[Python-3000] Making more effective use of slice objects in Py3k (original) (raw)
Guido van Rossum guido at python.org
Wed Aug 30 00:04:09 CEST 2006
- Previous message: [Python-3000] Making more effective use of slice objects in Py3k
- Next message: [Python-3000] Making more effective use of slice objects in Py3k
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 8/29/06, Jim Jewett <jimjjewett at gmail.com> wrote:
On 8/29/06, Guido van Rossum <guido at python.org> wrote: > On 8/29/06, Josiah Carlson <jcarlson at uci.edu> wrote: > > "Guido van Rossum" <guido at python.org> wrote:
> The type consistency and predictability is more important to me. Why is it essential that string views be a different type, rather than an internal implementation detail, like long vs int? Today's strings can already return a new object or an existing one which happens to be equal. Is this just a matter of efficiency, or are you making a fundamental distinction?
Sigh. Josiah just said he wouldn't dream of proposing that all string ops should return string views. You're not helping by questioning even that.
The short answer is, if you don't have control over when a view on an existing string is returned and when a copy, there are easy to see worst-case behaviors that are worse than the problem they are trying to fix. For example, you'd get a whole series of problems like this one:
res = [] for i in range(1000): s = " "*1000000 # a new 1MB string res.append(s[:1]) # a one-character string that is a view on s and hence keeps s alive
if s[:1] were to return a view on s unconditionally the above loop would accumumate roughly 1 GB in wasted space.
To fix this you'll have to add heuristics and all sorts of other things and that will complicate the string implementation and hence slow it down.
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-3000] Making more effective use of slice objects in Py3k
- Next message: [Python-3000] Making more effective use of slice objects in Py3k
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]