<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On 30 sep 2013, at 20:47, Martin Nowak <<a href="mailto:dawg@dawgfoto.de">dawg@dawgfoto.de</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<div bgcolor="#FFFFFF" text="#000000">
The runtime support for string foreach with decoding has some
serious performance issues.<br>
It's currently implemented by creating a delegate for the foreach
body and calling _aApply*.<br>
I recently submitted this pull to vibe.d
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<a href="https://github.com/rejectedsoftware/vibe.d/pull/327">https://github.com/rejectedsoftware/vibe.d/pull/327</a>.<br>
Using the explicit for (auto tmp = s; !tmp.empty; tmp.popFront()) {
auto c = tmp.front; /*CODE*/ }<br>
is about 3 times faster.<br>
I'd like to avoid such hidden performance pitfalls. Any ideas how to
transition to templated library code?<br>
For dchar iteration the compiler could simply prefer the range
interface, but that wouldn't work for wchar (or char with
w/dstrings).<br>
Is it something that should only be added to phobos, e.g. foreach
(c; s.byChar!dchar())?<br>
Or should this be a combination of compiler and library support,
i.e. when an explicit char type is given the compiler<br>
instantiates a template with that char type.</div></blockquote></div><div><br></div><div>I don't see why "byChar" should be added. It's better to fix the current implementation. If I recall correctly, also "foreach(c ; s)" is the same as foreach over dchar. Which is an even more hidden pitfall.</div><br><div>
<span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px; ">-- <br>/Jacob Carlborg</span>
</div>
<br></body></html>