Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save the allocation of a closure and allow delegate caching in case scheduling on CurrentThreadScheduler is required. #566

Merged
merged 2 commits into from
Jun 1, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 6 additions & 29 deletions Rx.NET/Source/src/System.Reactive/Internal/Producer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ public IDisposable SubscribeRaw(IObserver<TSource> observer, bool enableSafeguar

if (CurrentThreadScheduler.IsScheduleRequired)
{
var state = new State { subscription = subscription, observer = observer };
CurrentThreadScheduler.Instance.Schedule(state, Run);
CurrentThreadScheduler.Instance.ScheduleAction(
(@this: this, subscription, observer),
tuple => tuple.subscription.Disposable = tuple.@this.Run(tuple.observer));
}
else
{
Expand All @@ -62,18 +63,6 @@ public IDisposable SubscribeRaw(IObserver<TSource> observer, bool enableSafeguar
return subscription;
}

private struct State
{
public SingleAssignmentDisposable subscription;
public IObserver<TSource> observer;
}

private IDisposable Run(IScheduler _, State x)
{
x.subscription.Disposable = Run(x.observer);
return Disposable.Empty;
}

/// <summary>
/// Core implementation of the query operator, called upon a new subscription to the producer object.
/// </summary>
Expand Down Expand Up @@ -118,9 +107,9 @@ public IDisposable SubscribeRaw(IObserver<TTarget> observer, bool enableSafeguar

if (CurrentThreadScheduler.IsScheduleRequired)
{
var state = new State { sink = sink, inner = subscription.Inner };

CurrentThreadScheduler.Instance.Schedule(state, Run);
CurrentThreadScheduler.Instance.ScheduleAction(
(@this: this, sink, inner: subscription.Inner),
tuple => tuple.inner.Disposable = tuple.@this.Run(tuple.sink));
}
else
{
Expand All @@ -130,18 +119,6 @@ public IDisposable SubscribeRaw(IObserver<TTarget> observer, bool enableSafeguar
return subscription;
}

private struct State
{
public TSink sink;
public SingleAssignmentDisposable inner;
}

private IDisposable Run(IScheduler _, State x)
{
x.inner.Disposable = Run(x.sink);
return Disposable.Empty;
}

/// <summary>
/// Core implementation of the query operator, called upon a new subscription to the producer object.
/// </summary>
Expand Down