From d4ea988ee839320e54e4b87f9bd3eaf7738b90c2 Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Fri, 6 Jul 2018 17:38:49 +0200 Subject: [PATCH] Save the allocation of a SingleAssignmentDisposable in CombineLatest. --- .../Linq/Observable/CombineLatest.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Rx.NET/Source/src/System.Reactive/Linq/Observable/CombineLatest.cs b/Rx.NET/Source/src/System.Reactive/Linq/Observable/CombineLatest.cs index dfd896e9db..29499816e8 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/Observable/CombineLatest.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/Observable/CombineLatest.cs @@ -431,11 +431,10 @@ public void Run(IEnumerable> sources) { var j = i; - var d = new SingleAssignmentDisposable(); - _subscriptions[j] = d; - var o = new SourceObserver(this, j); - d.Disposable = srcs[j].SubscribeSafe(o); + _subscriptions[j] = o; + + o.SetResource(srcs[j].SubscribeSafe(o)); } SetUpstream(StableCompositeDisposable.CreateTrusted(_subscriptions)); @@ -496,7 +495,7 @@ private void OnCompleted(int index) } } - private sealed class SourceObserver : IObserver + private sealed class SourceObserver : SafeObserver { private readonly _ _parent; private readonly int _index; @@ -507,17 +506,17 @@ public SourceObserver(_ parent, int index) _index = index; } - public void OnNext(TSource value) + public override void OnNext(TSource value) { _parent.OnNext(_index, value); } - public void OnError(Exception error) + public override void OnError(Exception error) { _parent.OnError(error); } - public void OnCompleted() + public override void OnCompleted() { _parent.OnCompleted(_index); }