Skip to content

Commit

Permalink
Refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmada committed Aug 7, 2020
1 parent bbfa765 commit a4e0e6d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
6 changes: 5 additions & 1 deletion NetFabric.Hyperlinq/Generation/Return.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ public ReturnEnumerable<TResult> Select<TResult>(NullableSelector<TSource, TResu

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Option<TSource> ElementAt(int index)
=> index == 0 ? Option.Some(value) : Option.None;
=> index switch
{
0 => Option.Some(value),
_ => Option.None,
};

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Option<TSource> First()
Expand Down
11 changes: 7 additions & 4 deletions NetFabric.Hyperlinq/Option/Option.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public bool IsNone


public readonly bool Contains(T value, IEqualityComparer<T>? comparer = default)
=> IsSome && (comparer is null
=> IsSome &&
(comparer is null
? EqualityComparer<T>.Default.Equals(Value!, value)
: comparer.Equals(Value!, value));

Expand Down Expand Up @@ -139,9 +140,11 @@ public bool IsNone

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly Option<T> ElementAt(int index)
=> index == 0
? this
: default;
=> index switch
{
0 => this,
_ => default,
};


[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
6 changes: 5 additions & 1 deletion NetFabric.Hyperlinq/Set/Distinct/Set.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ public bool Add([AllowNull] TElement value)
Debug.Assert(buckets is object);
Debug.Assert(slots is object);

var hashCode = value is null ? 0 : comparer.GetHashCode(value) & 0x7FFFFFFF;
var hashCode = value switch
{
null => 0,
_ => comparer.GetHashCode(value) & 0x7FFFFFFF,
};
if (Utils.IsValueType<TElement>() && ReferenceEquals(comparer, EqualityComparer<TElement>.Default))
{
for (var index = buckets[hashCode % buckets.Length] - 1; index >= 0; index = slots[index].Next)
Expand Down
6 changes: 5 additions & 1 deletion NetFabric.Hyperlinq/Utils/ArrayBuilder/ArrayBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ void EnsureCapacity(int minimum)
Debug.Assert(minimum > Capacity);

var capacity = Capacity;
var nextCapacity = capacity == 0 ? DefaultMinCapacity : 2 * capacity;
var nextCapacity = capacity switch
{
0 => DefaultMinCapacity,
_ => 2 * capacity,
};

if ((uint)nextCapacity > (uint)MaxCoreClrArrayLength)
{
Expand Down

0 comments on commit a4e0e6d

Please sign in to comment.