Skip to content

Commit

Permalink
Update EquivalentTo to test length & null for equality as well
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Aug 4, 2020
1 parent 794f136 commit 540d406
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/ServiceStack.Common/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ public static T FirstNonDefault<T>(this IEnumerable<T> values)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool EquivalentTo(this byte[] bytes, byte[] other)
{
if (bytes == null || other == null)
return bytes == other;

if (bytes.Length != other.Length)
return false;

var compare = 0;
for (var i = 0; i < other.Length; i++)
compare |= other[i] ^ bytes[i];
Expand Down

0 comments on commit 540d406

Please sign in to comment.