Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,34 +137,50 @@ private static bool Compare(TElem[]? a, TElem[]? b, ValueComparer<TElem> element
return false;
}

if (ReferenceEquals(a, b))
{
return true;
}

// Note: the following currently boxes every element access because ValueComparer isn't really
// generic (see https://github.com/aspnet/EntityFrameworkCore/issues/11072)
for (var i = 0; i < a.Length; i++)
{
if (!elementComparer.Equals(a[i], b[i]))
{
return false;
}
}

return true;
}

private static int GetHashCode(TElem[] source, ValueComparer<TElem> elementComparer)
{
var hash = new HashCode();

foreach (var el in source)
{
hash.Add(el, elementComparer);
}

return hash.ToHashCode();
}

[return: NotNullIfNotNull("source")]
private static TElem[]? Snapshot(TElem[]? source, ValueComparer<TElem> elementComparer)
{
if (source == null)
if (source is null)
return null;

var snapshot = new TElem[source.Length];
// Note: the following currently boxes every element access because ValueComparer isn't really
// generic (see https://github.com/aspnet/EntityFrameworkCore/issues/11072)
for (var i = 0; i < source.Length; i++)
{
snapshot[i] = elementComparer.Snapshot(source[i])!; // TODO: https://github.com/dotnet/efcore/pull/24410
}

return snapshot;
}
}
Expand All @@ -191,6 +207,11 @@ private static bool Compare(TElem?[]? a, TElem?[]? b, ValueComparer<TElem> eleme
return false;
}

if (ReferenceEquals(a, b))
{
return true;
}

// Note: the following currently boxes every element access because ValueComparer isn't really
// generic (see https://github.com/aspnet/EntityFrameworkCore/issues/11072)
for (var i = 0; i < a.Length; i++)
Expand All @@ -199,11 +220,17 @@ private static bool Compare(TElem?[]? a, TElem?[]? b, ValueComparer<TElem> eleme
if (el1 is null)
{
if (el2 is null)
{
continue;
}

return false;
}

if (el2 is null || !elementComparer.Equals(el1, el2))
{
return false;
}
}

return true;
Expand All @@ -213,22 +240,31 @@ private static int GetHashCode(TElem?[] source, ValueComparer<TElem> elementComp
{
var nullableEqualityComparer = new NullableEqualityComparer<TElem>(elementComparer);
var hash = new HashCode();

foreach (var el in source)
{
hash.Add(el, nullableEqualityComparer);
}

return hash.ToHashCode();
}

[return: NotNullIfNotNull("source")]
private static TElem?[]? Snapshot(TElem?[]? source, ValueComparer<TElem> elementComparer)
{
if (source == null)
if (source is null)
{
return null;
}

var snapshot = new TElem?[source.Length];
// Note: the following currently boxes every element access because ValueComparer isn't really
// generic (see https://github.com/aspnet/EntityFrameworkCore/issues/11072)
for (var i = 0; i < source.Length; i++)
snapshot[i] = source[i] is { } value ? elementComparer.Snapshot(value) : (TElem?)null;
{
snapshot[i] = source[i] is { } value ? elementComparer.Snapshot(value) : null;
}

return snapshot;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,34 +135,51 @@ private static bool Compare(List<TElem>? a, List<TElem>? b, ValueComparer<TElem>
return false;
}

if (ReferenceEquals(a, b))
{
return true;
}

// Note: the following currently boxes every element access because ValueComparer isn't really
// generic (see https://github.com/aspnet/EntityFrameworkCore/issues/11072)
for (var i = 0; i < a.Count; i++)
{
if (!elementComparer.Equals(a[i], b[i]))
{
return false;
}
}

return true;
}

private static int GetHashCode(List<TElem> source, ValueComparer<TElem> elementComparer)
{
var hash = new HashCode();

foreach (var el in source)
{
hash.Add(el, elementComparer);
}

return hash.ToHashCode();
}

private static List<TElem>? Snapshot(List<TElem>? source, ValueComparer<TElem> elementComparer)
{
if (source == null)
if (source is null)
{
return null;
}

var snapshot = new List<TElem>(source.Count);

// Note: the following currently boxes every element access because ValueComparer isn't really
// generic (see https://github.com/aspnet/EntityFrameworkCore/issues/11072)
foreach (var e in source)
{
snapshot.Add(elementComparer.Snapshot(e)!); // TODO: https://github.com/dotnet/efcore/pull/24410
}

return snapshot;
}
Expand Down Expand Up @@ -191,6 +208,11 @@ private static bool Compare(List<TElem?>? a, List<TElem?>? b, ValueComparer<TEle
return false;
}

if (ReferenceEquals(a, b))
{
return true;
}

// Note: the following currently boxes every element access because ValueComparer isn't really
// generic (see https://github.com/aspnet/EntityFrameworkCore/issues/11072)
for (var i = 0; i < a.Count; i++)
Expand All @@ -199,11 +221,17 @@ private static bool Compare(List<TElem?>? a, List<TElem?>? b, ValueComparer<TEle
if (el1 is null)
{
if (el2 is null)
{
continue;
}

return false;
}

if (el2 is null || !elementComparer.Equals(a[i], b[i]))
{
return false;
}
}

return true;
Expand All @@ -213,22 +241,30 @@ private static int GetHashCode(List<TElem?> source, ValueComparer<TElem> element
{
var nullableEqualityComparer = new NullableEqualityComparer<TElem>(elementComparer);
var hash = new HashCode();

foreach (var el in source)
{
hash.Add(el, nullableEqualityComparer);
}

return hash.ToHashCode();
}

private static List<TElem?>? Snapshot(List<TElem?>? source, ValueComparer<TElem> elementComparer)
{
if (source == null)
{
return null;
}

var snapshot = new List<TElem?>(source.Count);

// Note: the following currently boxes every element access because ValueComparer isn't really
// generic (see https://github.com/aspnet/EntityFrameworkCore/issues/11072)
foreach (var e in source)
snapshot.Add(e is { } value ? elementComparer.Snapshot(value) : (TElem?)null);
{
snapshot.Add(e is { } value ? elementComparer.Snapshot(value) : null);
}

return snapshot;
}
Expand Down