Skip to content

Commit

Permalink
Simplify variable declaration/init
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz committed Aug 13, 2020
1 parent cca9227 commit 3d602b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion MoreLinq/CountBy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ bool TryGetIndex(TKey key, out int i)

keys = new List<TKey>();
counts = new List<int>();
var prevKey = (false, default(TKey));
(bool, TKey) prevKey = default;
var index = 0;

foreach (var item in source)
Expand Down
26 changes: 13 additions & 13 deletions MoreLinq/PendNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ sealed class Source : PendNode<T>
public IEnumerator<T> 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)
Expand All @@ -87,10 +87,10 @@ public IEnumerator<T> 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;
Expand All @@ -108,10 +108,10 @@ public IEnumerator<T> 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;
}

Expand Down

0 comments on commit 3d602b9

Please sign in to comment.