From 1c43c5c8f8752314f3d3e267c96ef95dc07dbc0f Mon Sep 17 00:00:00 2001 From: Peter Wehrfritz Date: Fri, 6 Jul 2018 10:45:41 +0200 Subject: [PATCH] Introduce a common base class for the single values, and resolve some rebase conflicts. --- .../Linq/Observable/AppendPrepend.cs | 70 +++++++------------ .../Linq/QueryLanguage.Single.cs | 4 +- 2 files changed, 26 insertions(+), 48 deletions(-) diff --git a/Rx.NET/Source/src/System.Reactive/Linq/Observable/AppendPrepend.cs b/Rx.NET/Source/src/System.Reactive/Linq/Observable/AppendPrepend.cs index 2e78b8d66d..6346d33608 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/Observable/AppendPrepend.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/Observable/AppendPrepend.cs @@ -16,20 +16,20 @@ internal interface IAppendPrepend : IObservable IScheduler Scheduler { get; } } - internal sealed class SingleValue : Producer, IAppendPrepend + internal abstract class SingleBase : Producer, IAppendPrepend + where TSink : IDisposable { - private readonly IObservable _source; - private readonly TSource _value; - private readonly bool _append; + protected readonly IObservable _source; + protected readonly TSource _value; + protected readonly bool _append; - public IScheduler Scheduler { get; } + public abstract IScheduler Scheduler { get; } - public SingleValue(IObservable source, TSource value, IScheduler scheduler, bool append) + public SingleBase(IObservable source, TSource value, bool append) { _source = source; _value = value; _append = append; - Scheduler = scheduler; } public IAppendPrepend Append(TSource value) @@ -79,6 +79,18 @@ private IAppendPrepend CreateAppendPrepend(Node prepend, Node return new Recursive(_source, prepend, append, Scheduler); } + } + + + internal sealed class SingleValue : SingleBase + { + public override IScheduler Scheduler { get; } + + public SingleValue(IObservable source, TSource value, IScheduler scheduler, bool append) + : base (source, value, append) + { + Scheduler = scheduler; + } protected override _ CreateSink(IObserver observer) => new _(this, observer); @@ -479,47 +491,13 @@ public T[] ToReverseArray() } } - internal sealed class AppendPrependSingleImmediate : Producer._>, IAppendPrepend + internal sealed class SingleImmediate : SingleBase { - private readonly IObservable _source; - private readonly TSource _value; - private readonly bool _append; - - public IScheduler Scheduler { get { return ImmediateScheduler.Instance; } } - - public AppendPrependSingleImmediate(IObservable source, TSource value, bool append) - { - _source = source; - _value = value; - _append = append; - } - - public IAppendPrepend Append(TSource value) - { - var prev = new Node(_value); - - if (_append) - { - return new AppendPrependMultiple(_source, - null, new Node(prev, value), Scheduler); - } - - return new AppendPrependMultiple(_source, - prev, new Node(value), Scheduler); - } + public override IScheduler Scheduler => ImmediateScheduler.Instance; - public IAppendPrepend Prepend(TSource value) + public SingleImmediate(IObservable source, TSource value, bool append) + : base(source, value, append) { - var prev = new Node(_value); - - if (_append) - { - return new AppendPrependMultiple(_source, - new Node(value), prev, Scheduler); - } - - return new AppendPrependMultiple(_source, - new Node(prev, value), null, Scheduler); } protected override _ CreateSink(IObserver observer) => new _(this, observer); @@ -532,7 +510,7 @@ internal sealed class _ : IdentitySink private readonly TSource _value; private readonly bool _append; - public _(AppendPrependSingleImmediate parent, IObserver observer) + public _(SingleImmediate parent, IObserver observer) : base(observer) { _source = parent._source; diff --git a/Rx.NET/Source/src/System.Reactive/Linq/QueryLanguage.Single.cs b/Rx.NET/Source/src/System.Reactive/Linq/QueryLanguage.Single.cs index 186fca779e..e80b5bf123 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/QueryLanguage.Single.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/QueryLanguage.Single.cs @@ -32,7 +32,7 @@ private static IObservable Append_(IObservable source } if (scheduler == ImmediateScheduler.Instance) { - return new AppendPrepend.SingleImmediate(source, value, true); + return new AppendPrepend.SingleImmediate(source, value, append: true); } return new AppendPrepend.SingleValue(source, value, scheduler, append: true); } @@ -213,7 +213,7 @@ private static IObservable Prepend_(IObservable sourc if (scheduler == ImmediateScheduler.Instance) { - return new AppendPrepend.AppendPrependSingleImmediate(source, value, false); + return new AppendPrepend.SingleImmediate(source, value, append: false); } return new AppendPrepend.SingleValue(source, value, scheduler, append: false);