Skip to content

Commit 37d8c1a

Browse files
committed
Use MemoryExtensions.SequenceEqual in a few more places
1 parent 91e06c0 commit 37d8c1a

File tree

4 files changed

+6
-69
lines changed

4 files changed

+6
-69
lines changed

src/libraries/System.Data.Common/src/System/Data/DataKey.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,20 +168,9 @@ internal bool Equals(DataKey value)
168168
{
169169
return false;
170170
}
171-
else if (column1.Length != column2.Length)
172-
{
173-
return false;
174-
}
175171
else
176172
{
177-
for (int i = 0; i < column1.Length; i++)
178-
{
179-
if (!column1[i].Equals(column2[i]))
180-
{
181-
return false;
182-
}
183-
}
184-
return true;
173+
return column1.AsSpan().SequenceEqual(column2);
185174
}
186175
}
187176

src/libraries/System.Data.Common/src/System/Data/RelatedView.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,7 @@ public bool Invoke(DataRow row, DataRowVersion version)
6262

6363
object[] childValues = row.GetKeyValues(_childKey, version);
6464

65-
bool allow = true;
66-
if (childValues.Length != parentValues.Length)
67-
{
68-
allow = false;
69-
}
70-
else
71-
{
72-
for (int i = 0; i < childValues.Length; i++)
73-
{
74-
if (!childValues[i].Equals(parentValues[i]))
75-
{
76-
allow = false;
77-
break;
78-
}
79-
}
80-
}
65+
bool allow = childValues.AsSpan().SequenceEqual(parentValues);
8166

8267
IFilter? baseFilter = base.GetFilter();
8368
if (baseFilter != null)

src/libraries/System.IO.UnmanagedMemoryStream/tests/ArrayHelpers.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,7 @@ private ArrayComparer() // use the static Instance singleton
5353
{
5454
}
5555

56-
public bool Equals(T[] x, T[] y)
57-
{
58-
if (x.Length != y.Length)
59-
{
60-
return false;
61-
}
62-
for (int i = 0; i < x.Length; i++)
63-
{
64-
if (!EqualityComparer<T>.Default.Equals(x[i], y[i]))
65-
{
66-
return false;
67-
}
68-
}
69-
return true;
70-
}
56+
public bool Equals(T[] x, T[] y) => x.AsSpan().SequenceEqual(y);
7157

7258
public int GetHashCode(T[] obj)
7359
{

src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.cs

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -827,38 +827,15 @@ public bool HasSameRules(TimeZoneInfo other)
827827
return false;
828828
}
829829

830-
bool sameRules;
831830
AdjustmentRule[]? currentRules = _adjustmentRules;
832831
AdjustmentRule[]? otherRules = other._adjustmentRules;
833832

834-
sameRules =
835-
(currentRules == null && otherRules == null) ||
836-
(currentRules != null && otherRules != null);
837-
838-
if (!sameRules)
833+
if (currentRules is null || otherRules is null)
839834
{
840-
// AdjustmentRule array mismatch
841-
return false;
835+
return currentRules == otherRules;
842836
}
843837

844-
if (currentRules != null)
845-
{
846-
if (currentRules.Length != otherRules!.Length)
847-
{
848-
// AdjustmentRule array length mismatch
849-
return false;
850-
}
851-
852-
for (int i = 0; i < currentRules.Length; i++)
853-
{
854-
if (!(currentRules[i]).Equals(otherRules[i]))
855-
{
856-
// AdjustmentRule value-equality mismatch
857-
return false;
858-
}
859-
}
860-
}
861-
return sameRules;
838+
return currentRules.AsSpan().SequenceEqual(otherRules);
862839
}
863840

864841
/// <summary>

0 commit comments

Comments
 (0)