[D-runtime] foreach (dchar c; s) is too slow

Jacob Carlborg doob at me.com
Wed Oct 2 00:29:07 PDT 2013


On Oct 01, 2013, at 08:13 PM, Jonathan M Davis <jmdavisProg at gmx.com> wrote:

> The range API won't even work on arrays unless std.array has been imported,
> and in the case of strings, it depends on std.utf. So, using the range
> interface underneat the hood for
>
> foreach(dchar c; str)
>
> would require Phobos. I'd argue for simply fixing how foreach for strings works
> so that it doesn't use opApply. Worst case, some druntime-specific functions
> could be written and used to do it, though that would probably require changes
> in the compiler. But if you want to use a range of some kind, just create one
> for each character type, and the fact that Phobos treats strings as ranges of
> dchar should be irrelevant. It does that by having traits like hasLength and
> isNarrowString treat them that way. There's no reason why you can't have a
> range of char or wchar if you want to, and if druntime is wrapping strings in
> ranges for foreach, then it can trivially create a range type which treats
> strings as ranges of whatever character type you want just so long as front
> and popFront do the appropriate conversion. Probably another thing to consider
> in all this is how to deal with foreach_reverse, but that can probably be
> dealt with as well.
>
> I don't particularly like the fact that we're forced to duplicate std.utf stuff
> in druntime in order to handle foreach, but I don't know of any way around
> that short of moving std.utf (or some portion of it) into druntime. It's
> pretty much the same problem that we have with the fact that std.traits isn't
> available in druntime, except that the implementation for decode and stride
> are a bit more complicated than most traits.

Can't we move some of the functionality to druntime? It doesn't need to be duplicated. Move what we can to druntime and publicly import that in Phobos.

--
/Jacob Carlborg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/d-runtime/attachments/20131002/8cb26d00/attachment.html>


More information about the D-runtime mailing list