On Sun, Oct 27, 2019, at 03:10, Andrew Barnert wrote:
> On Oct 26, 2019, at 19:59, Random832 <random...@fastmail.com> wrote:
> > 
> > A string representation considering of (say) a UTF-8 string, plus an 
> > auxiliary list of byte indices of, say, 256-codepoint-long chunks [along 
> > with perhaps a flag to say that the chunk is all-ASCII or not] would 
> > provide O(1) random access, though, of course, despite both being O(1), 
> > "single index access" vs "single index access then either another index 
> > access or up to 256 iterate-forward operations" aren't *really* the same 
> > speed.
> 
> Yes, but that means constructing a string takes linear time, because 
> you have to construct that index. You can’t just take a 
> read/recv/mmap/result of a C library/whatever and use it as a string 
> without doing linear work on it first. 

constructing a string already takes linear time because you have to copy it 
into memory managed by the python garbage collector. And you can track whether 
you'll need the index in one pass while copying, rather than, as currently, 
having to do one pass to pick a representation and another to actually perform 
the copying and conversion, so my suggestion may have a cache locality 
advantage over the other way.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/UY5IIRWPSB37XRKDHLJYECIIFWPZS5SN/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to