From de5f19291c64545fee063c4c9e3a63c36c97c9a4 Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Thu, 31 May 2018 22:20:59 +0200 Subject: [PATCH] BasicProducer/Producer: Save the allocation of a closure and allow delegate caching in case scheduling on CurrentThreadScheduler is required. --- .../src/System.Reactive/Internal/Producer.cs | 35 ++++--------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/Rx.NET/Source/src/System.Reactive/Internal/Producer.cs b/Rx.NET/Source/src/System.Reactive/Internal/Producer.cs index 9b6d522380..6ec12f45bf 100644 --- a/Rx.NET/Source/src/System.Reactive/Internal/Producer.cs +++ b/Rx.NET/Source/src/System.Reactive/Internal/Producer.cs @@ -51,8 +51,9 @@ public IDisposable SubscribeRaw(IObserver 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 { @@ -62,18 +63,6 @@ public IDisposable SubscribeRaw(IObserver observer, bool enableSafeguar return subscription; } - private struct State - { - public SingleAssignmentDisposable subscription; - public IObserver observer; - } - - private IDisposable Run(IScheduler _, State x) - { - x.subscription.Disposable = Run(x.observer); - return Disposable.Empty; - } - /// /// Core implementation of the query operator, called upon a new subscription to the producer object. /// @@ -118,9 +107,9 @@ public IDisposable SubscribeRaw(IObserver 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 { @@ -130,18 +119,6 @@ public IDisposable SubscribeRaw(IObserver 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; - } - /// /// Core implementation of the query operator, called upon a new subscription to the producer object. ///