Skip to content

Commit 5300e81

Browse files
committed
Remove redundant checks that cause warnings in modern .NET
1 parent 7d84fef commit 5300e81

8 files changed

Lines changed: 15 additions & 94 deletions

File tree

src/F23.StringSimilarity/Damerau.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
namespace F23.StringSimilarity
3232
{
3333
/// <summary>
34-
/// Implementation of Damerau-Levenshtein distance with transposition (also
34+
/// Implementation of Damerau-Levenshtein distance with transposition (also
3535
/// sometimes calls unrestricted Damerau-Levenshtein distance).
3636
/// It is the minimum number of operations needed to transform one string into
3737
/// the other, where an operation is defined as an insertion, deletion, or
@@ -59,16 +59,6 @@ public double Distance(string s1, string s2)
5959
public double Distance<T>(ReadOnlySpan<T> s1, ReadOnlySpan<T> s2)
6060
where T : IEquatable<T>
6161
{
62-
if (s1 == null)
63-
{
64-
throw new ArgumentNullException(nameof(s1));
65-
}
66-
67-
if (s2 == null)
68-
{
69-
throw new ArgumentNullException(nameof(s2));
70-
}
71-
7262
if (s1.SequenceEqual(s2))
7363
{
7464
return 0;

src/F23.StringSimilarity/F23.StringSimilarity.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<IncludeSymbols>true</IncludeSymbols>
1818
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
1919
<Version>8.0.0-alpha</Version>
20+
<LangVersion>14</LangVersion>
2021
</PropertyGroup>
2122
<PropertyGroup Label="Assembly signing" Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
2223
<DefineConstants>FEATURE_SIGNED_ASSEMBLY;$(DefineConstants)</DefineConstants>

src/F23.StringSimilarity/JaroWinkler.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ public class JaroWinkler : INormalizedStringSimilarity, INormalizedStringDistanc
4949
/// The current value of the threshold used for adding the Winkler bonus. The default value is 0.7.
5050
/// </summary>
5151
private double Threshold { get; }
52-
52+
5353
/// <summary>
5454
/// Creates a new instance with default threshold (0.7)
5555
/// </summary>
5656
public JaroWinkler()
5757
{
5858
Threshold = DEFAULT_THRESHOLD;
5959
}
60-
60+
6161
/// <summary>
6262
/// Creates a new instance with given threshold to determine when Winkler bonus should
6363
/// be used. Set threshold to a negative value to get the Jaro distance.
@@ -77,20 +77,10 @@ public JaroWinkler(double threshold)
7777
/// <exception cref="ArgumentNullException">If s1 or s2 is null.</exception>
7878
public double Similarity(string s1, string s2)
7979
=> Similarity(s1.AsSpan(), s2.AsSpan());
80-
80+
8181
public double Similarity<T>(ReadOnlySpan<T> s1, ReadOnlySpan<T> s2)
8282
where T : IEquatable<T>
8383
{
84-
if (s1 == null)
85-
{
86-
throw new ArgumentNullException(nameof(s1));
87-
}
88-
89-
if (s2 == null)
90-
{
91-
throw new ArgumentNullException(nameof(s2));
92-
}
93-
9484
if (s1.SequenceEqual(s2))
9585
{
9686
return 1f;
@@ -122,7 +112,7 @@ public double Similarity<T>(ReadOnlySpan<T> s1, ReadOnlySpan<T> s2)
122112
/// <exception cref="ArgumentNullException">If s1 or s2 is null.</exception>
123113
public double Distance(string s1, string s2)
124114
=> 1.0 - Similarity(s1, s2);
125-
115+
126116
public double Distance<T>(ReadOnlySpan<T> s1, ReadOnlySpan<T> s2)
127117
where T : IEquatable<T>
128118
=> 1.0 - Similarity(s1, s2);
@@ -202,7 +192,7 @@ private static int[] Matches<T>(ReadOnlySpan<T> s1, ReadOnlySpan<T> s2)
202192
break;
203193
}
204194
}
205-
return new[] { matches, transpositions / 2, prefix, max.Length };
195+
return [matches, transpositions / 2, prefix, max.Length];
206196
}
207197
}
208198
}

src/F23.StringSimilarity/Levenshtein.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,14 @@ public class Levenshtein : IMetricStringDistance, IMetricSpanDistance
7373
/// <exception cref="ArgumentNullException">If s1 or s2 is null.</exception>
7474
public double Distance(string s1, string s2, int limit)
7575
=> Distance(s1.AsSpan(), s2.AsSpan(), limit);
76-
76+
7777
public double Distance<T>(ReadOnlySpan<T> s1, ReadOnlySpan<T> s2)
7878
where T : IEquatable<T>
7979
=> Distance(s1, s2, int.MaxValue);
80-
80+
8181
public double Distance<T>(ReadOnlySpan<T> s1, ReadOnlySpan<T> s2, int limit)
8282
where T : IEquatable<T>
8383
{
84-
if (s1 == null)
85-
{
86-
throw new ArgumentNullException(nameof(s1));
87-
}
88-
89-
if (s2 == null)
90-
{
91-
throw new ArgumentNullException(nameof(s2));
92-
}
93-
9484
if (s1.SequenceEqual(s2))
9585
{
9686
return 0;

src/F23.StringSimilarity/LongestCommonSubsequence.cs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,10 @@ public class LongestCommonSubsequence : IStringDistance, ISpanDistance
5959
/// <exception cref="ArgumentNullException">If s1 or s2 is null.</exception>
6060
public double Distance(string s1, string s2)
6161
=> Distance(s1.AsSpan(), s2.AsSpan());
62-
62+
6363
public double Distance<T>(ReadOnlySpan<T> s1, ReadOnlySpan<T> s2)
6464
where T : IEquatable<T>
6565
{
66-
if (s1 == null)
67-
{
68-
throw new ArgumentNullException(nameof(s1));
69-
}
70-
71-
if (s2 == null)
72-
{
73-
throw new ArgumentNullException(nameof(s2));
74-
}
75-
7666
if (s1.SequenceEqual(s2))
7767
{
7868
return 0;
@@ -91,20 +81,10 @@ public double Distance<T>(ReadOnlySpan<T> s1, ReadOnlySpan<T> s2)
9181
/// <exception cref="ArgumentNullException">If s1 or s2 is null.</exception>
9282
public int Length(string s1, string s2)
9383
=> Length(s1.AsSpan(), s2.AsSpan());
94-
84+
9585
internal static int Length<T>(ReadOnlySpan<T> s1, ReadOnlySpan<T> s2)
9686
where T : IEquatable<T>
9787
{
98-
if (s1 == null)
99-
{
100-
throw new ArgumentNullException(nameof(s1));
101-
}
102-
103-
if (s2 == null)
104-
{
105-
throw new ArgumentNullException(nameof(s2));
106-
}
107-
10888
/* function LCSLength(X[1..m], Y[1..n])
10989
C = array(0..m, 0..n)
11090
for i := 0..m

src/F23.StringSimilarity/MetricLCS.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,10 @@ public class MetricLCS : IMetricStringDistance, INormalizedStringDistance, IMetr
4343
/// <exception cref="ArgumentNullException">If s1 or s2 is null.</exception>
4444
public double Distance(string s1, string s2)
4545
=> Distance(s1.AsSpan(), s2.AsSpan());
46-
46+
4747
public double Distance<T>(ReadOnlySpan<T> s1, ReadOnlySpan<T> s2)
4848
where T : IEquatable<T>
4949
{
50-
if (s1 == null)
51-
{
52-
throw new ArgumentNullException(nameof(s1));
53-
}
54-
55-
if (s2 == null)
56-
{
57-
throw new ArgumentNullException(nameof(s2));
58-
}
59-
6050
if (s1.SequenceEqual(s2))
6151
{
6252
return 0;

src/F23.StringSimilarity/NormalizedLevenshtein.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,10 @@ public class NormalizedLevenshtein : INormalizedStringDistance, INormalizedStrin
4444
/// <exception cref="ArgumentNullException">If s1 or s2 is null.</exception>
4545
public double Distance(string s1, string s2)
4646
=> Distance(s1.AsSpan(), s2.AsSpan());
47-
47+
4848
public double Distance<T>(ReadOnlySpan<T> s1, ReadOnlySpan<T> s2)
4949
where T : IEquatable<T>
5050
{
51-
if (s1 == null)
52-
{
53-
throw new ArgumentNullException(nameof(s1));
54-
}
55-
56-
if (s2 == null)
57-
{
58-
throw new ArgumentNullException(nameof(s2));
59-
}
60-
6151
if (s1.SequenceEqual(s2))
6252
{
6353
return 0.0;
@@ -82,7 +72,7 @@ public double Distance<T>(ReadOnlySpan<T> s1, ReadOnlySpan<T> s2)
8272
/// <exception cref="ArgumentNullException">If s1 or s2 is null.</exception>
8373
public double Similarity(string s1, string s2)
8474
=> 1.0 - Distance(s1, s2);
85-
75+
8676
public double Similarity<T>(ReadOnlySpan<T> s1, ReadOnlySpan<T> s2)
8777
where T : IEquatable<T>
8878
=> 1.0 - Distance(s1, s2);

src/F23.StringSimilarity/OptimalStringAlignment.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,10 @@ public sealed class OptimalStringAlignment : IStringDistance, ISpanDistance
4343
/// <exception cref="ArgumentNullException">If s1 or s2 is null.</exception>
4444
public double Distance(string s1, string s2)
4545
=> Distance(s1.AsSpan(), s2.AsSpan());
46-
46+
4747
public double Distance<T>(ReadOnlySpan<T> s1, ReadOnlySpan<T> s2)
4848
where T : IEquatable<T>
4949
{
50-
if (s1 == null)
51-
{
52-
throw new ArgumentNullException(nameof(s1));
53-
}
54-
55-
if (s2 == null)
56-
{
57-
throw new ArgumentNullException(nameof(s2));
58-
}
59-
6050
if (s1.SequenceEqual(s2))
6151
{
6252
return 0;

0 commit comments

Comments
 (0)