Skip to content

Commit

Permalink
Refactor to eliminate redundant call to r.empty.
Browse files Browse the repository at this point in the history
.savePrev and .prev should be private.
  • Loading branch information
H. S. Teoh committed Oct 6, 2014
1 parent 70bec52 commit 95f143f
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions std/algorithm.d
Expand Up @@ -4523,14 +4523,14 @@ private struct GroupByImpl(alias equivFun, Range)
static if (isForwardRange!Range)
{
private Range _prev;
void savePrev() { _prev = r.save; }
@property ElementType!Range prev() { return _prev.front; }
private void savePrev() { _prev = r.save; }
private @property ElementType!Range prev() { return _prev.front; }
}
else
{
private ElementType!Range _prev;
void savePrev() { _prev = r.front; }
alias prev = _prev;
private void savePrev() { _prev = r.front; }
private alias prev = _prev;
}

this(Range _r)
Expand All @@ -4554,10 +4554,15 @@ private struct GroupByImpl(alias equivFun, Range)

void popFront()
{
while (!r.empty && equiv(prev, r.front))
while (!r.empty)
{
if (!equiv(prev, r.front))
{
savePrev();
return;
}
r.popFront();
if (!r.empty)
savePrev();
}
}

static if (isForwardRange!Range)
Expand Down

0 comments on commit 95f143f

Please sign in to comment.