Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 525fea0

Browse files
committed
chore: code cleanup
1 parent 2940ed8 commit 525fea0

39 files changed

Lines changed: 355 additions & 340 deletions

NewType.Benchmark/Benchmarks/CollectionBenchmarks.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using BenchmarkDotNet.Attributes;
2-
using BenchmarkDotNet.Columns;
32
using BenchmarkDotNet.Configs;
43

54
namespace newtype.benchmark;
@@ -32,7 +31,7 @@ public void Setup()
3231
for (var i = 0; i < N; i++)
3332
{
3433
_rawDict[i] = i;
35-
_aliasDict[(EntityId)i] = i;
34+
_aliasDict[(EntityId) i] = i;
3635
}
3736

3837
_rawKey = N / 2;
@@ -78,4 +77,4 @@ public void SortSetup()
7877

7978
[Benchmark, BenchmarkCategory("Sort")]
8079
public void Sort_Alias() => Array.Sort(_aliasSortBuffer);
81-
}
80+
}

NewType.Benchmark/Benchmarks/ConstructionBenchmarks.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Numerics;
22
using BenchmarkDotNet.Attributes;
3-
using BenchmarkDotNet.Columns;
43
using BenchmarkDotNet.Configs;
54

65
namespace newtype.benchmark;
@@ -63,4 +62,4 @@ public void Setup()
6362

6463
[Benchmark, BenchmarkCategory("RecordStruct_Implicit")]
6564
public Score Implicit_RecordStruct_Alias() => _intVal;
66-
}
65+
}

NewType.Benchmark/Benchmarks/ConversionBenchmarks.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Numerics;
22
using BenchmarkDotNet.Attributes;
3-
using BenchmarkDotNet.Columns;
43
using BenchmarkDotNet.Configs;
54

65
namespace newtype.benchmark;
@@ -69,4 +68,4 @@ public void Setup()
6968

7069
[Benchmark, BenchmarkCategory("RecordStruct_FromAlias")]
7170
public int FromAlias_RecordStruct_Alias() => _score;
72-
}
71+
}

NewType.Benchmark/Benchmarks/GenericConstraintBenchmarks.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using System.Runtime.CompilerServices;
22
using BenchmarkDotNet.Attributes;
3-
using BenchmarkDotNet.Columns;
43
using BenchmarkDotNet.Configs;
5-
using BenchmarkDotNet.Diagnosers;
64

75
namespace newtype.benchmark;
86

@@ -39,7 +37,7 @@ public void Setup()
3937
public bool Contains_Raw() => Contains(_rawArr, 512);
4038

4139
[Benchmark, BenchmarkCategory("Contains")]
42-
public bool Contains_Alias() => Contains(_aliasArr, (EntityId)512);
40+
public bool Contains_Alias() => Contains(_aliasArr, (EntityId) 512);
4341

4442
// --- Generic min (IComparable<T>) ---
4543
[Benchmark(Baseline = true), BenchmarkCategory("GenericMin")]
@@ -76,15 +74,16 @@ public void SortSetup()
7674
public int CountEq_Raw() => CountEqual(_rawArr, 0);
7775

7876
[Benchmark, BenchmarkCategory("CountEq")]
79-
public int CountEq_Alias() => CountEqual(_aliasArr, (EntityId)0);
77+
public int CountEq_Alias() => CountEqual(_aliasArr, (EntityId) 0);
8078

8179
// --- Helpers: generic with struct constraints for devirtualization ---
8280

8381
[MethodImpl(MethodImplOptions.NoInlining)]
8482
private static bool Contains<T>(T[] arr, T value) where T : struct, IEquatable<T>
8583
{
8684
for (var i = 0; i < arr.Length; i++)
87-
if (arr[i].Equals(value)) return true;
85+
if (arr[i].Equals(value))
86+
return true;
8887
return false;
8988
}
9089

@@ -93,7 +92,8 @@ private static T FindMin<T>(T[] arr) where T : struct, IComparable<T>
9392
{
9493
var min = arr[0];
9594
for (var i = 1; i < arr.Length; i++)
96-
if (arr[i].CompareTo(min) < 0) min = arr[i];
95+
if (arr[i].CompareTo(min) < 0)
96+
min = arr[i];
9797
return min;
9898
}
9999

@@ -109,6 +109,7 @@ private static void InsertionSort<T>(T[] arr) where T : struct, IComparable<T>
109109
arr[j + 1] = arr[j];
110110
j--;
111111
}
112+
112113
arr[j + 1] = key;
113114
}
114115
}
@@ -118,7 +119,8 @@ private static int CountEqual<T>(T[] arr, T value) where T : struct, IEquatable<
118119
{
119120
var count = 0;
120121
for (var i = 0; i < arr.Length; i++)
121-
if (arr[i].Equals(value)) count++;
122+
if (arr[i].Equals(value))
123+
count++;
122124
return count;
123125
}
124-
}
126+
}

NewType.Benchmark/Benchmarks/InliningChainBenchmarks.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
using System.Numerics;
22
using BenchmarkDotNet.Attributes;
3-
using BenchmarkDotNet.Columns;
43
using BenchmarkDotNet.Configs;
5-
using BenchmarkDotNet.Diagnosers;
64

75
namespace newtype.benchmark;
86

@@ -26,12 +24,22 @@ public class InliningChainBenchmarks
2624
[GlobalSetup]
2725
public void Setup()
2826
{
29-
_a = 17; _b = 42; _c = 9; _d = 3; _e = 100;
30-
_aA = _a; _bA = _b; _cA = _c; _dA = _d; _eA = _e;
27+
_a = 17;
28+
_b = 42;
29+
_c = 9;
30+
_d = 3;
31+
_e = 100;
32+
_aA = _a;
33+
_bA = _b;
34+
_cA = _c;
35+
_dA = _d;
36+
_eA = _e;
3137
_v1 = new Vector3(1, 2, 3);
3238
_v2 = new Vector3(4, 5, 6);
3339
_v3 = new Vector3(7, 8, 9);
34-
_p1 = _v1; _p2 = _v2; _p3 = _v3;
40+
_p1 = _v1;
41+
_p2 = _v2;
42+
_p3 = _v3;
3543
_s = 0.5f;
3644
}
3745

@@ -69,4 +77,4 @@ public void Setup()
6977

7078
[Benchmark, BenchmarkCategory("Vec3Sum")]
7179
public Position Vec3Sum_Alias() => _p1 + _p2 + _p3;
72-
}
80+
}

NewType.Benchmark/Benchmarks/LoopComputeBenchmarks.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using BenchmarkDotNet.Attributes;
2-
using BenchmarkDotNet.Columns;
32
using BenchmarkDotNet.Configs;
4-
using BenchmarkDotNet.Diagnosers;
53

64
namespace newtype.benchmark;
75

@@ -89,7 +87,8 @@ public int Min_Raw()
8987
var arr = _rawArr;
9088
var min = arr[0];
9189
for (var i = 1; i < arr.Length; i++)
92-
if (arr[i] < min) min = arr[i];
90+
if (arr[i] < min)
91+
min = arr[i];
9392
return min;
9493
}
9594

@@ -99,7 +98,8 @@ public EntityId Min_Alias()
9998
var arr = _aliasArr;
10099
var min = arr[0];
101100
for (var i = 1; i < arr.Length; i++)
102-
if (arr[i] < min) min = arr[i];
101+
if (arr[i] < min)
102+
min = arr[i];
103103
return min;
104104
}
105105

@@ -123,4 +123,4 @@ public EntityId MulAcc_Alias()
123123
sum += arr[i] * i;
124124
return sum;
125125
}
126-
}
126+
}

NewType.Benchmark/Benchmarks/PrimitiveArithmeticBenchmarks.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using BenchmarkDotNet.Attributes;
2-
using BenchmarkDotNet.Columns;
32
using BenchmarkDotNet.Configs;
4-
using BenchmarkDotNet.Diagnosers;
53

64
namespace newtype.benchmark;
75

@@ -93,4 +91,4 @@ public void Setup()
9391

9492
[Benchmark, BenchmarkCategory("Neg")]
9593
public EntityId Neg_Alias() => -_aliasA;
96-
}
94+
}

NewType.Benchmark/Benchmarks/PrimitiveComparisonBenchmarks.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using BenchmarkDotNet.Attributes;
2-
using BenchmarkDotNet.Columns;
32
using BenchmarkDotNet.Configs;
43

54
namespace newtype.benchmark;
@@ -42,4 +41,4 @@ public void Setup()
4241

4342
[Benchmark, BenchmarkCategory("CompareTo")]
4443
public int CompareTo_Alias() => _aliasA.CompareTo(_aliasB);
45-
}
44+
}

NewType.Benchmark/Benchmarks/PrimitiveEqualityBenchmarks.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using BenchmarkDotNet.Attributes;
2-
using BenchmarkDotNet.Columns;
32
using BenchmarkDotNet.Configs;
43

54
namespace newtype.benchmark;
@@ -42,4 +41,4 @@ public void Setup()
4241

4342
[Benchmark, BenchmarkCategory("Equals")]
4443
public bool Equals_Alias() => _aliasA.Equals(_aliasB);
45-
}
44+
}

NewType.Benchmark/Benchmarks/PrimitiveHashingBenchmarks.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using BenchmarkDotNet.Attributes;
2-
using BenchmarkDotNet.Columns;
32
using BenchmarkDotNet.Configs;
43

54
namespace newtype.benchmark;
@@ -25,4 +24,4 @@ public void Setup()
2524

2625
[Benchmark, BenchmarkCategory("GetHashCode")]
2726
public int GetHashCode_Alias() => _aliasA.GetHashCode();
28-
}
27+
}

0 commit comments

Comments
 (0)