On Wed, Dec 19, 2018 at 10:38:06AM -0500, Steven Schveighoffer via 
Digitalmars-d-learn wrote:
[...]
> Looking at the code for chunkBy, it seems to me that the
> implementation is quite complex for what in my head should be a simple
> wrapper...
[...]

It was originally a simple wrapper when I first submitted it, but Andrei
requested to use RefCounted in order to work around the subrange
traversal problem. I.e., in the original implementation, the underlying
range traversed twice, once when each subrange is consumed, and once
when you call popFront on the outer range. Having RefCounted allows us
to retain a reference to the original range so that subranges will also
advance the underlying range as seen by the outer range, thereby
eliminating calling popFront on the underlying range twice per element.


T

-- 
People who are more than casually interested in computers should have at least 
some idea of what the underlying hardware is like. Otherwise the programs they 
write will be pretty weird. -- D. Knuth

Reply via email to