From 3d602b90c26cc543fd2837d87ae24a823c06caad Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Thu, 13 Aug 2020 14:57:31 +0200 Subject: [PATCH] Simplify variable declaration/init --- MoreLinq/CountBy.cs | 2 +- MoreLinq/PendNode.cs | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/MoreLinq/CountBy.cs b/MoreLinq/CountBy.cs index 00266c6e7..7aa62f502 100644 --- a/MoreLinq/CountBy.cs +++ b/MoreLinq/CountBy.cs @@ -94,7 +94,7 @@ bool TryGetIndex(TKey key, out int i) keys = new List(); counts = new List(); - var prevKey = (false, default(TKey)); + (bool, TKey) prevKey = default; var index = 0; foreach (var item in source) diff --git a/MoreLinq/PendNode.cs b/MoreLinq/PendNode.cs index 9da48e859..34dcdbb7b 100644 --- a/MoreLinq/PendNode.cs +++ b/MoreLinq/PendNode.cs @@ -62,11 +62,11 @@ sealed class Source : PendNode public IEnumerator GetEnumerator() { var i = 0; - T[]? concats = null; // Array for > 4 concatenations - var concat1 = default(T); // Slots for up to 4 concatenations - var concat2 = default(T); - var concat3 = default(T); - var concat4 = default(T); + T[]? concats = null; // Array for > 4 concatenations + (bool, T Value) concat1 = default; // Slots for up to 4 concatenations + (bool, T Value) concat2 = default; + (bool, T Value) concat3 = default; + (bool, T Value) concat4 = default; var current = this; for (; current is Item item; current = item.Next) @@ -87,10 +87,10 @@ public IEnumerator GetEnumerator() { switch (i++) { - case 0: concat1 = item.Value; break; - case 1: concat2 = item.Value; break; - case 2: concat3 = item.Value; break; - case 3: concat4 = item.Value; break; + case 0: concat1 = (true, item.Value); break; + case 1: concat2 = (true, item.Value); break; + case 2: concat3 = (true, item.Value); break; + case 3: concat4 = (true, item.Value); break; default: throw new IndexOutOfRangeException(); } continue; @@ -108,10 +108,10 @@ public IEnumerator GetEnumerator() if (concats == null) { - if (i == 4) { yield return concat4!; i--; } - if (i == 3) { yield return concat3!; i--; } - if (i == 2) { yield return concat2!; i--; } - if (i == 1) { yield return concat1!; i--; } + if (i == 4) { yield return concat4.Value; i--; } + if (i == 3) { yield return concat3.Value; i--; } + if (i == 2) { yield return concat2.Value; i--; } + if (i == 1) { yield return concat1.Value; i--; } yield break; }