use constructors instead of move

This commit is contained in:
aG0aep6G 2019-03-29 14:57:58 +01:00
parent 5c10e1faf5
commit b8610beec3
3 changed files with 89 additions and 66 deletions

View file

@ -1641,6 +1641,12 @@ if (isInputRange!R)
if (!_input.empty) popFront(); if (!_input.empty) popFront();
} }
private this(R input, Tuple!(MutableE, uint) current)
{
_input = input;
_current = current;
}
/// ///
void popFront() void popFront()
{ {
@ -1686,12 +1692,7 @@ if (isInputRange!R)
/// ///
@property typeof(this) save() @property typeof(this) save()
{ {
import std.algorithm.mutation : move; return Group(_input.save, _current);
typeof(this) ret = this;
auto saved = this._input.save;
move(saved, ret._input);
ret._current = this._current;
return ret;
} }
} }
} }
@ -5161,6 +5162,24 @@ private struct SplitterResult(alias isTerminator, Range)
_end = size_t.max; _end = size_t.max;
} }
static if (fullSlicing)
{
private this(Range input, size_t end)
{
_input = input;
_end = end;
}
}
else
{
private this(Range input, size_t end, Range next)
{
_input = input;
_end = end;
_next = next;
}
}
static if (isInfinite!Range) static if (isInfinite!Range)
{ {
enum bool empty = false; // Propagate infiniteness. enum bool empty = false; // Propagate infiniteness.
@ -5225,16 +5244,10 @@ private struct SplitterResult(alias isTerminator, Range)
@property typeof(this) save() @property typeof(this) save()
{ {
import std.algorithm.mutation : move; static if (fullSlicing)
auto ret = this; return SplitterResult(_input.save, _end);
auto savedInput = _input.save; else
move(savedInput, ret._input); return SplitterResult(_input.save, _end, _next.save);
static if (!fullSlicing)
{
auto savedNext = _next.save;
move(savedNext, ret._next);
}
return ret;
} }
} }

View file

@ -4921,6 +4921,7 @@ if (isInputRange!Range)
private bool _done; private bool _done;
static if (!is(Sentinel == void)) static if (!is(Sentinel == void))
{
/// ///
this(Range input, Sentinel sentinel, this(Range input, Sentinel sentinel,
OpenRight openRight = Yes.openRight) OpenRight openRight = Yes.openRight)
@ -4930,7 +4931,17 @@ if (isInputRange!Range)
_openRight = openRight; _openRight = openRight;
_done = _input.empty || openRight && predSatisfied(); _done = _input.empty || openRight && predSatisfied();
} }
private this(Range input, Sentinel sentinel, OpenRight openRight,
bool done)
{
_input = input;
_sentinel = sentinel;
_openRight = openRight;
_done = done;
}
}
else else
{
/// ///
this(Range input, OpenRight openRight = Yes.openRight) this(Range input, OpenRight openRight = Yes.openRight)
{ {
@ -4938,6 +4949,13 @@ if (isInputRange!Range)
_openRight = openRight; _openRight = openRight;
_done = _input.empty || openRight && predSatisfied(); _done = _input.empty || openRight && predSatisfied();
} }
private this(Range input, OpenRight openRight, bool done)
{
_input = input;
_openRight = openRight;
_done = done;
}
}
/// ///
@property bool empty() @property bool empty()
@ -4979,31 +4997,14 @@ if (isInputRange!Range)
static if (isForwardRange!Range) static if (isForwardRange!Range)
{ {
static if (!is(Sentinel == void)) ///
/// @property Until save()
@property Until save() {
{ static if (is(Sentinel == void))
import std.algorithm.mutation : move; return Until(_input.save, _openRight, _done);
Until result = this; else
auto saved = _input.save; return Until(_input.save, _sentinel, _openRight, _done);
move(saved, result._input); }
result._sentinel = _sentinel;
result._openRight = _openRight;
result._done = _done;
return result;
}
else
///
@property Until save()
{
import std.algorithm.mutation : move;
Until result = this;
auto saved = _input.save;
move(saved, result._input);
result._openRight = _openRight;
result._done = _done;
return result;
}
} }
} }

View file

@ -972,14 +972,20 @@ if (Ranges.length > 0 &&
static if (allSatisfy!(isForwardRange, R)) static if (allSatisfy!(isForwardRange, R))
@property auto save() @property auto save()
{ {
import std.algorithm.mutation : move; auto saveSource(size_t len)()
typeof(this) result = this;
foreach (i, Unused; R)
{ {
auto saved = result.source[i].save; import std.typecons : tuple;
move(saved, result.source[i]); static if (len == 0)
{
return tuple();
}
else
{
return saveSource!(len - 1)() ~
tuple(source[len - 1].save);
}
} }
return result; return Result(saveSource!(R.length).expand);
} }
void popFront() void popFront()
@ -1523,13 +1529,9 @@ private struct ChooseResult(R1, R2)
static if (isForwardRange!R1 && isForwardRange!R2) static if (isForwardRange!R1 && isForwardRange!R2)
@property auto save() @property auto save()
{ {
auto result = this; return r1Chosen
actOnChosen!((ref r) { ? ChooseResult(r1Chosen, r1.save, r2)
import std.algorithm.mutation : move; : ChooseResult(r1Chosen, r1, r2.save);
auto saved = r.save;
move(saved, r);
})(result);
return result;
} }
@property void front(T)(T v) @property void front(T)(T v)
@ -1844,14 +1846,20 @@ if (Rs.length > 1 && allSatisfy!(isInputRange, staticMap!(Unqual, Rs)))
static if (allSatisfy!(isForwardRange, staticMap!(Unqual, Rs))) static if (allSatisfy!(isForwardRange, staticMap!(Unqual, Rs)))
@property auto save() @property auto save()
{ {
import std.algorithm.mutation : move; auto saveSource(size_t len)()
Result result = this;
foreach (i, Unused; Rs)
{ {
auto saved = result.source[i].save; import std.typecons : tuple;
move(saved, result.source[i]); static if (len == 0)
{
return tuple();
}
else
{
return saveSource!(len - 1)() ~
tuple(source[len - 1].save);
}
} }
return result; return Result(saveSource!(Rs.length).expand, _current);
} }
static if (allSatisfy!(hasLength, Rs)) static if (allSatisfy!(hasLength, Rs))
@ -3782,6 +3790,12 @@ if (isForwardRange!R && !isInfinite!R)
_current = input.save; _current = input.save;
} }
private this(R original, R current)
{
_original = original;
_current = current;
}
/// ditto /// ditto
@property auto ref front() @property auto ref front()
{ {
@ -3820,13 +3834,8 @@ if (isForwardRange!R && !isInfinite!R)
/// ditto /// ditto
@property Cycle save() @property Cycle save()
{ {
import std.algorithm.mutation : move;
//No need to call _original.save, because Cycle never actually modifies _original //No need to call _original.save, because Cycle never actually modifies _original
Cycle ret = this; return Cycle(_original, _current.save);
ret._original = _original;
auto saved = _current.save;
move(saved, _current);
return ret;
} }
} }
} }