[Refactor] Optimize LINQ queries.

This commit is contained in:
2025-11-24 11:45:16 +00:00
parent 46066fb9a7
commit 7af8b40f80
11 changed files with 35 additions and 37 deletions

View File

@@ -525,8 +525,8 @@ sealed partial class Dump
}
if(!outputOptical.OpticalCapabilities.HasFlag(OpticalImageCapabilities.CanStorePregaps) &&
tracks.Where(track => track.Sequence != tracks.First(t => t.Session == track.Session).Sequence)
.Any(static track => track.Pregap > 0))
tracks.Any(track => track.Sequence != tracks.First(t => t.Session == track.Session).Sequence &&
track.Pregap > 0))
{
if(!_force)
{
@@ -1084,8 +1084,9 @@ sealed partial class Dump
foreach(int sub in _resume.BadSubchannels) subchannelExtents.Add(sub);
if(_resume.NextBlock < blocks)
for(ulong i = _resume.NextBlock; i < blocks; i++)
subchannelExtents.Add((int)i);
{
for(ulong i = _resume.NextBlock; i < blocks; i++) subchannelExtents.Add((int)i);
}
}
if(_resume.NextBlock > 0)
@@ -1511,8 +1512,9 @@ sealed partial class Dump
supportsLongSectors);
foreach(Tuple<ulong, ulong> leadoutExtent in leadOutExtents.ToArray())
for(ulong e = leadoutExtent.Item1; e <= leadoutExtent.Item2; e++)
subchannelExtents.Remove((int)e);
{
for(ulong e = leadoutExtent.Item1; e <= leadoutExtent.Item2; e++) subchannelExtents.Remove((int)e);
}
if(subchannelExtents.Count > 0 && _retryPasses > 0 && _retrySubchannel)
{

View File

@@ -191,8 +191,8 @@ partial class Dump
if(oldToc.HasValue)
{
foreach(TOC.CDTOCTrackDataDescriptor trk in oldToc.Value.TrackDescriptors
.OrderBy(static t => t.TrackNumber)
.Where(static trk => trk.ADR is 1 or 4))
.Where(static trk => trk.ADR is 1 or 4)
.OrderBy(static t => t.TrackNumber))
{
switch(trk.TrackNumber)
{

View File

@@ -156,8 +156,7 @@ public sealed class Entropy
EndProgress2Event?.Invoke();
trackEntropy.Entropy += entTable.Select(l => l / (double)trackSize)
.Select(static frequency => -(frequency * Math.Log(frequency, 2)))
.Sum();
.Sum(static frequency => -(frequency * Math.Log(frequency, 2)));
if(duplicatedSectors) trackEntropy.UniqueSectors = uniqueSectorsPerTrack.Count;
@@ -230,8 +229,7 @@ public sealed class Entropy
EndProgressEvent?.Invoke();
entropy.Entropy += entTable.Select(l => l / (double)diskSize)
.Select(static frequency => -(frequency * Math.Log(frequency, 2)))
.Sum();
.Sum(static frequency => -(frequency * Math.Log(frequency, 2)));
if(duplicatedSectors) entropy.UniqueSectors = uniqueSectors.Count;
@@ -277,8 +275,7 @@ public sealed class Entropy
EndProgressEvent?.Invoke();
entropy.Entropy += entTable.Select(l => l / (double)data.Length)
.Select(static frequency => -(frequency * Math.Log(frequency, 2)))
.Sum();
.Sum(static frequency => -(frequency * Math.Log(frequency, 2)));
return entropy;
}

View File

@@ -167,7 +167,8 @@ public static class Partitions
// Be sure that device partitions are not excluded if not mapped by any scheme...
if(tapeImage is not null)
{
var startLocations = childPartitions.Select(static detectedPartition => detectedPartition.Start).ToList();
List<ulong> startLocations =
childPartitions.ConvertAll(static detectedPartition => detectedPartition.Start);
if(tapeImage.Files != null)
{
@@ -183,7 +184,8 @@ public static class Partitions
if(partitionableImage is not null)
{
var startLocations = childPartitions.Select(static detectedPartition => detectedPartition.Start).ToList();
List<ulong> startLocations =
childPartitions.ConvertAll(static detectedPartition => detectedPartition.Start);
if(partitionableImage.Partitions != null)
{