From b77f914d670f7cd645af9e497a2f68dc13a5ce7b Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Tue, 3 Jul 2018 12:25:34 +0200 Subject: [PATCH 1/2] Cleanup of more code redundancies that ReSharper suggested. --- .../Scheduler.Services.Emulation.cs | 8 +----- .../Concurrency/Scheduler.Services.cs | 2 +- .../Linq/Observable/CombineLatest.cs | 1 - .../Linq/Observable/SelectMany.cs | 28 ++++++------------- 4 files changed, 10 insertions(+), 29 deletions(-) diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.Emulation.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.Emulation.cs index f1577ef660..403596edd7 100644 --- a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.Emulation.cs +++ b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.Emulation.cs @@ -396,8 +396,6 @@ private void Tick(Action, TimeSpan> recurse) while (true) { - var shouldWaitForResume = false; - lock (_gate) { if (_runState == RUNNING) @@ -430,7 +428,6 @@ private void Tick(Action, TimeSpan> recurse) // will pick up the cumulative inactive time delta. // Debug.Assert(_runState == SUSPENDED); - shouldWaitForResume = true; } // @@ -440,10 +437,7 @@ private void Tick(Action, TimeSpan> recurse) // be extremely unlucky to find ourselves SUSPENDED again and be blocked // once more. // - if (shouldWaitForResume) - { - _resumeEvent.WaitOne(); - } + _resumeEvent.WaitOne(); } recurse(this, next); diff --git a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.cs b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.cs index 6979a46eb5..f4e2b325de 100644 --- a/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.cs +++ b/Rx.NET/Source/src/System.Reactive/Concurrency/Scheduler.Services.cs @@ -13,7 +13,7 @@ public static partial class Scheduler internal static Type[] OPTIMIZATIONS = { typeof(ISchedulerLongRunning), typeof(IStopwatchProvider), - typeof(ISchedulerPeriodic), + typeof(ISchedulerPeriodic) /* update this list if new interface-based optimizations are added */ }; 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 2fc6a03c01..426fb9b535 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/Observable/CombineLatest.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/Observable/CombineLatest.cs @@ -179,7 +179,6 @@ public void OnNext(TSecond value) else if (_other.Done) { _parent.ForwardOnCompleted(); - return; } } } diff --git a/Rx.NET/Source/src/System.Reactive/Linq/Observable/SelectMany.cs b/Rx.NET/Source/src/System.Reactive/Linq/Observable/SelectMany.cs index b6a7babc0f..67b05f5fd3 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/Observable/SelectMany.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/Observable/SelectMany.cs @@ -395,9 +395,9 @@ public override void OnNext(TSource value) try { var hasNext = true; + while (hasNext) { - hasNext = false; var current = default(TResult); try @@ -422,10 +422,7 @@ public override void OnNext(TSource value) } finally { - if (e != null) - { - e.Dispose(); - } + e.Dispose(); } } } @@ -492,9 +489,9 @@ public override void OnNext(TSource value) { var eIndex = 0; var hasNext = true; + while (hasNext) { - hasNext = false; var current = default(TResult); try @@ -519,10 +516,7 @@ public override void OnNext(TSource value) } finally { - if (e != null) - { - e.Dispose(); - } + e.Dispose(); } } } @@ -1370,9 +1364,9 @@ public override void OnNext(TSource value) try { var hasNext = true; + while (hasNext) { - hasNext = false; var current = default(TResult); try @@ -1397,10 +1391,7 @@ public override void OnNext(TSource value) } finally { - if (e != null) - { - e.Dispose(); - } + e.Dispose(); } } } @@ -1460,9 +1451,9 @@ public override void OnNext(TSource value) try { var hasNext = true; + while (hasNext) { - hasNext = false; var current = default(TResult); try @@ -1487,10 +1478,7 @@ public override void OnNext(TSource value) } finally { - if (e != null) - { - e.Dispose(); - } + e.Dispose(); } } } From 5acc0c47e9b04bbe24f26de5abc2751ab51a4aa4 Mon Sep 17 00:00:00 2001 From: Daniel Weber Date: Tue, 3 Jul 2018 12:31:05 +0200 Subject: [PATCH 2/2] Replace try-finally by using. --- .../Linq/Observable/SelectMany.cs | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/Rx.NET/Source/src/System.Reactive/Linq/Observable/SelectMany.cs b/Rx.NET/Source/src/System.Reactive/Linq/Observable/SelectMany.cs index 67b05f5fd3..20380cfc49 100644 --- a/Rx.NET/Source/src/System.Reactive/Linq/Observable/SelectMany.cs +++ b/Rx.NET/Source/src/System.Reactive/Linq/Observable/SelectMany.cs @@ -392,7 +392,7 @@ public override void OnNext(TSource value) return; } - try + using (e) { var hasNext = true; @@ -420,10 +420,6 @@ public override void OnNext(TSource value) } } } - finally - { - e.Dispose(); - } } } } @@ -485,7 +481,7 @@ public override void OnNext(TSource value) return; } - try + using (e) { var eIndex = 0; var hasNext = true; @@ -514,10 +510,6 @@ public override void OnNext(TSource value) } } } - finally - { - e.Dispose(); - } } } } @@ -1361,7 +1353,7 @@ public override void OnNext(TSource value) return; } - try + using (e) { var hasNext = true; @@ -1389,10 +1381,6 @@ public override void OnNext(TSource value) } } } - finally - { - e.Dispose(); - } } } } @@ -1448,7 +1436,7 @@ public override void OnNext(TSource value) return; } - try + using (e) { var hasNext = true; @@ -1476,10 +1464,6 @@ public override void OnNext(TSource value) } } } - finally - { - e.Dispose(); - } } } }