On Tue, 11 Mar 2014 10:06:47 -0400, Dicebot <[email protected]> wrote:
On Tuesday, 11 March 2014 at 14:04:38 UTC, Steven Schveighoffer wrote:
It would be O(1), work just like it does today.
-Steve
Today it works by allowing arbitrary index and not checking if resulting
slice is valid UTF-8. Anything that implies decoding is O(n). What
exactly do you have in mind for this?
Well, a valid improvement would be to throw an exception when the slice
didn't start/end on a valid code point. This is easily checkable in O(1)
time, but I wouldn't recommend it to begin with, it may have huge
performance issues. Typically, one does not arbitrarily slice up via some
specific value, they use a function to get an index, and they don't care
what the index value actually is.
Alternatively, it could be done via assert, to disable it during release
mode. This might be acceptable.
But I would never expect any kind of indexing or slicing to use "number of
code points", which clearly requires O(n) decoding to determine it's
position. That would be disastrous.
-Steve