Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from Tuple to ValueTuple for Dictionary keys #5554

Merged
merged 1 commit into from
Jan 8, 2024
Merged
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 @@ -60,7 +60,7 @@ public LockFile CreateLockFile(LockFile previousLockFile,
Version = _lockFileVersion
};

var previousLibraries = previousLockFile?.Libraries.ToDictionary(l => Tuple.Create(l.Name, l.Version));
var previousLibraries = previousLockFile?.Libraries.ToDictionary(l => ValueTuple.Create(l.Name, l.Version));

if (project.RestoreMetadata?.ProjectStyle == ProjectStyle.PackageReference ||
project.RestoreMetadata?.ProjectStyle == ProjectStyle.DotnetToolReference)
Expand Down Expand Up @@ -139,7 +139,7 @@ public LockFile CreateLockFile(LockFile previousLockFile,
LockFileLibrary lockFileLib = null;
LockFileLibrary previousLibrary = null;

if (previousLibraries?.TryGetValue(Tuple.Create(package.Id, package.Version), out previousLibrary) == true)
if (previousLibraries?.TryGetValue(ValueTuple.Create(package.Id, package.Version), out previousLibrary) == true)
{
// Check that the previous library is still valid
if (previousLibrary != null
Expand All @@ -165,7 +165,7 @@ public LockFile CreateLockFile(LockFile previousLockFile,
}
}

Dictionary<Tuple<string, NuGetVersion>, LockFileLibrary> libraries = EnsureUniqueLockFileLibraries(lockFile);
Dictionary<ValueTuple<string, NuGetVersion>, LockFileLibrary> libraries = EnsureUniqueLockFileLibraries(lockFile);

var librariesWithWarnings = new HashSet<LibraryIdentity>();

Expand Down Expand Up @@ -233,7 +233,7 @@ public LockFile CreateLockFile(LockFile previousLockFile,

(LockFileTargetLibrary targetLibrary, bool usedFallbackFramework) = LockFileUtils.CreateLockFileTargetLibrary(
libraryDependency?.Aliases,
libraries[Tuple.Create(library.Name, library.Version)],
libraries[ValueTuple.Create(library.Name, library.Version)],
package,
targetGraph,
dependencyType: includeFlags,
Expand All @@ -253,7 +253,7 @@ public LockFile CreateLockFile(LockFile previousLockFile,

var targetLibraryWithoutFallback = LockFileUtils.CreateLockFileTargetLibrary(
libraryDependency?.Aliases,
libraries[Tuple.Create(library.Name, library.Version)],
libraries[ValueTuple.Create(library.Name, library.Version)],
package,
targetGraph,
targetFrameworkOverride: nonFallbackFramework,
Expand Down Expand Up @@ -302,14 +302,14 @@ public LockFile CreateLockFile(LockFile previousLockFile,
return lockFile;
}

private Dictionary<Tuple<string, NuGetVersion>, LockFileLibrary> EnsureUniqueLockFileLibraries(LockFile lockFile)
private Dictionary<ValueTuple<string, NuGetVersion>, LockFileLibrary> EnsureUniqueLockFileLibraries(LockFile lockFile)
{
IList<LockFileLibrary> libraries = lockFile.Libraries;
var libraryReferences = new Dictionary<Tuple<string, NuGetVersion>, LockFileLibrary>();
var libraryReferences = new Dictionary<ValueTuple<string, NuGetVersion>, LockFileLibrary>();

foreach (LockFileLibrary lib in libraries)
{
var libraryKey = Tuple.Create(lib.Name, lib.Version);
var libraryKey = ValueTuple.Create(lib.Name, lib.Version);

if (libraryReferences.TryGetValue(libraryKey, out LockFileLibrary existingLibrary))
{
Expand All @@ -328,7 +328,7 @@ private Dictionary<Tuple<string, NuGetVersion>, LockFileLibrary> EnsureUniqueLoc
if (lockFile.Libraries.Count != libraryReferences.Count)
{
lockFile.Libraries = new List<LockFileLibrary>(libraryReferences.Count);
foreach (KeyValuePair<Tuple<string, NuGetVersion>, LockFileLibrary> pair in libraryReferences)
foreach (KeyValuePair<ValueTuple<string, NuGetVersion>, LockFileLibrary> pair in libraryReferences)
{
lockFile.Libraries.Add(pair.Value);
}
Expand Down