joiner and map, strange behavior
Stephan Schiffels
stephan_schiffels at mac.com
Tue Mar 12 17:22:48 PDT 2013
Am 12.03.13 20:22, schrieb Timon Gehr:
> On 03/12/2013 06:51 PM, Stephan Schiffels wrote:
>> ...
>>
>> Thanks, I had a brief look at std.algorithm.joiner but couldn't find
>> anything obvious, maybe I should look deeper into it.
>> ...
>
> I guess it is because of the following:
>
> Eg (similar code occurs two times):
> ...
> if (_sep.empty)
> {
> // Advance to the next range in the
> // input
> //_items.popFront();
> for (;; _items.popFront())
> {
> if (_items.empty) return;
> if (!_items.front.empty) break; // front called
> }
> _current = _items.front; // front called again
> _items.popFront();
> }
> ...
>
> The code should only call front once for the first non-empty range.
>
> Presumed example fix (though the implementation seems rather clumsy and
> should probably be replaced completely):
>
> ...
> if (_sep.empty)
> {
> // Advance to the next range in the
> // input
> //_items.popFront();
> for (;; _items.popFront())
> {
> if (_items.empty) return;
> _current = _items.front;
> if (!_current.empty) break;
> }
> _items.popFront();
> }
> ...
Thanks, that's very clear now. I stumbled over it because the function I
call loads a lot of data and a factor 2 makes all the difference in
runtime. Maybe I should file a bug report or at least a request to
improve this.
Stephan
More information about the Digitalmars-d-learn
mailing list