On 08.05.2015 00:09, Neil Girdhar wrote:
This was a CPython idea after all, so I was assuming a C implementation, which means that new flags would have to be added to the string object to denote a string slice, etc.
Like I said in another message: it's not that important to me though. I was just curious as to why CPython was designed so that string slicing is linear rather than constant time given that strings are constant.
This was considered very early on in the Unicode type design, but dropped since the problem with such slices is that you have to keep a reference to the original string around which keeps this alive, even if you just use a slice of a few chars from it.
There are some situations where such a slicing mechanism would be nice to have, but in most of those you can simply work on the original string using an offset index.
Indeed, working with index tuples into the original string is often a better strategy.
You can see this used in mxTextTools:
to create high performance text parsing and manipulation tools.
I'm getting the impression that the payoff is not worth the complexity.
-- Marc-Andre Lemburg eGenix.com
Professional Python Services directly from the Source (#1, May 08 2015)
::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/