Skip to content

Commit e302692

Browse files
authored
Reduce enumerator boxing allocations in LockFileItem.Equals (#6994)
1 parent 71b5964 commit e302692

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/NuGet.Core/NuGet.ProjectModel/LockFile/LockFileItem.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,21 @@ public bool Equals(LockFileItem other)
5454

5555
if (string.Equals(Path, other.Path, StringComparison.OrdinalIgnoreCase))
5656
{
57-
return Properties.OrderedEquals(other.Properties, pair => pair.Key, StringComparer.Ordinal);
57+
// Handle null/empty dictionaries (treat them as equal)
58+
bool thisEmpty = _properties == null || _properties.Count == 0;
59+
bool otherEmpty = other._properties == null || other._properties.Count == 0;
60+
61+
if (thisEmpty && otherEmpty)
62+
{
63+
return true;
64+
}
65+
66+
if (thisEmpty || otherEmpty)
67+
{
68+
return false;
69+
}
70+
71+
return _properties.OrderedEquals(other._properties, pair => pair.Key, StringComparer.Ordinal);
5872
}
5973

6074
return false;

0 commit comments

Comments
 (0)