Narrow string is not a random access range
Jonathan M Davis
jmdavisProg at gmx.com
Wed Oct 24 04:54:36 PDT 2012
On Wednesday, October 24, 2012 13:19:54 mist wrote:
> Ok, just one question to make an official position clear: is
> commonPrefix implementation buggy or it is a conscious decision
> to go for some speed breaking correct operations on narrow
> strings at the same time?
Strings are always ranges of dchar, but if a function can operate on them more
efficiently by special casing them and then using array operations taking the
correct unicode handling into account, then it generally will.
commonPrefix can't make much more efficient by special casing strings, but it
_can_ change its return type to be a string via slicing, since it can keep
track of where it is in the string as it iterates over it. However, the
documentation incorrectly states that the result of commonPrefix is always
takeExactly. That's generally true but is _not_ true for strings. The
documentation needs to be fixed.
That being said, there _is_ a bug in commonPrefix that I just noticed when
looking it over. It currently operates on code units rather than code points.
It can operate on strings just fine like it's doing now (even returning a
slice), but it needs to decode the code points as it iterates over them, and
it's not doing that.
- Jonathna M Davis
More information about the Digitalmars-d-learn
mailing list