Skip to content

Commit

Permalink
Save some allocations by using a ValueTuple instead of a dedicated st…
Browse files Browse the repository at this point in the history
…ate class and passing state to IScheduler.Schedule. (#644)
  • Loading branch information
danielcweber authored Jun 25, 2018
1 parent 70d2a05 commit 69cf591
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void Run(ToObservable<TSource> parent)
// to observe the cancellation and perform proper clean-up. In this case,
// we're sure Loop will be entered, allowing us to dispose the enumerator.
//
SetUpstream(longRunning.ScheduleLongRunning(e, Loop));
SetUpstream(longRunning.ScheduleLongRunning((@this: this, e), (tuple, cancelable) => tuple.@this.Loop(tuple.e, cancelable)));
}
else
{
Expand All @@ -63,18 +63,20 @@ public void Run(ToObservable<TSource> parent)
// enumerator.
//
var flag = new BooleanDisposable();
parent._scheduler.Schedule(new State(flag, e), LoopRec);
parent._scheduler.Schedule(new State(this, flag, e), (state, action) => state.sink.LoopRec(state, action));
SetUpstream(flag);
}
}

private sealed class State
private struct State
{
public readonly _ sink;
public readonly ICancelable flag;
public readonly IEnumerator<TSource> enumerator;

public State(ICancelable flag, IEnumerator<TSource> enumerator)
public State(_ sink, ICancelable flag, IEnumerator<TSource> enumerator)
{
this.sink = sink;
this.flag = flag;
this.enumerator = enumerator;
}
Expand Down

0 comments on commit 69cf591

Please sign in to comment.