Skip to content

Commit

Permalink
Remove PackageComparer, it's not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced committed Mar 5, 2024
1 parent afcf8bf commit 87025c9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 31 deletions.
8 changes: 4 additions & 4 deletions src/DependencyGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace Chisel;
internal sealed class DependencyGraph
{
private readonly HashSet<Package> _roots;
private readonly Dictionary<Package, HashSet<Package>> _graph = new(PackageComparer.Instance);
private readonly Dictionary<Package, HashSet<Package>> _reverseGraph = new(PackageComparer.Instance);
private readonly Dictionary<Package, HashSet<Package>> _graph = new();
private readonly Dictionary<Package, HashSet<Package>> _reverseGraph = new();

private static Package CreatePackage(LockFileTargetLibrary library)
{
Expand Down Expand Up @@ -41,7 +41,7 @@ public DependencyGraph(string projectAssetsFile, string tfm, string rid)
};
var packages = target.Libraries.ToDictionary(e => e.Name ?? "", CreatePackage, StringComparer.OrdinalIgnoreCase);

_roots = new HashSet<Package>(framework.Dependencies.Select(e => packages[e.Name]), PackageComparer.Instance);
_roots = new HashSet<Package>(framework.Dependencies.Select(e => packages[e.Name]));

foreach (var package in packages.Values)
{
Expand Down Expand Up @@ -70,7 +70,7 @@ public DependencyGraph(string projectAssetsFile, string tfm, string rid)
{
var notFound = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
var removedRoots = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
var dependencies = new HashSet<Package>(PackageComparer.Instance);
var dependencies = new HashSet<Package>();
foreach (var packageName in packages.Distinct())
{
var packageDependency = _reverseGraph.Keys.SingleOrDefault(e => e.Name.Equals(packageName, StringComparison.OrdinalIgnoreCase));
Expand Down
11 changes: 8 additions & 3 deletions src/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ public Package(string name, string version, IReadOnlyCollection<string> dependen

public override string ToString() => Name;

public bool Equals(Package? other) => PackageComparer.Instance.Equals(this, other);
public bool Equals(Package? other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase);
}

public override bool Equals(object? other) => PackageComparer.Instance.Equals(this, other as Package);
public override bool Equals(object? obj) => ReferenceEquals(this, obj) || obj is Package other && Equals(other);

public override int GetHashCode() => PackageComparer.Instance.GetHashCode(this);
public override int GetHashCode() => Name.GetHashCode();
}
24 changes: 0 additions & 24 deletions src/PackageComparer.cs

This file was deleted.

0 comments on commit 87025c9

Please sign in to comment.