mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[Refactor] Optimize LINQ queries.
This commit is contained in:
@@ -525,8 +525,8 @@ sealed partial class Dump
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!outputOptical.OpticalCapabilities.HasFlag(OpticalImageCapabilities.CanStorePregaps) &&
|
if(!outputOptical.OpticalCapabilities.HasFlag(OpticalImageCapabilities.CanStorePregaps) &&
|
||||||
tracks.Where(track => track.Sequence != tracks.First(t => t.Session == track.Session).Sequence)
|
tracks.Any(track => track.Sequence != tracks.First(t => t.Session == track.Session).Sequence &&
|
||||||
.Any(static track => track.Pregap > 0))
|
track.Pregap > 0))
|
||||||
{
|
{
|
||||||
if(!_force)
|
if(!_force)
|
||||||
{
|
{
|
||||||
@@ -1084,8 +1084,9 @@ sealed partial class Dump
|
|||||||
foreach(int sub in _resume.BadSubchannels) subchannelExtents.Add(sub);
|
foreach(int sub in _resume.BadSubchannels) subchannelExtents.Add(sub);
|
||||||
|
|
||||||
if(_resume.NextBlock < blocks)
|
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)
|
if(_resume.NextBlock > 0)
|
||||||
@@ -1511,8 +1512,9 @@ sealed partial class Dump
|
|||||||
supportsLongSectors);
|
supportsLongSectors);
|
||||||
|
|
||||||
foreach(Tuple<ulong, ulong> leadoutExtent in leadOutExtents.ToArray())
|
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)
|
if(subchannelExtents.Count > 0 && _retryPasses > 0 && _retrySubchannel)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -191,8 +191,8 @@ partial class Dump
|
|||||||
if(oldToc.HasValue)
|
if(oldToc.HasValue)
|
||||||
{
|
{
|
||||||
foreach(TOC.CDTOCTrackDataDescriptor trk in oldToc.Value.TrackDescriptors
|
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)
|
switch(trk.TrackNumber)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -156,8 +156,7 @@ public sealed class Entropy
|
|||||||
EndProgress2Event?.Invoke();
|
EndProgress2Event?.Invoke();
|
||||||
|
|
||||||
trackEntropy.Entropy += entTable.Select(l => l / (double)trackSize)
|
trackEntropy.Entropy += entTable.Select(l => l / (double)trackSize)
|
||||||
.Select(static frequency => -(frequency * Math.Log(frequency, 2)))
|
.Sum(static frequency => -(frequency * Math.Log(frequency, 2)));
|
||||||
.Sum();
|
|
||||||
|
|
||||||
if(duplicatedSectors) trackEntropy.UniqueSectors = uniqueSectorsPerTrack.Count;
|
if(duplicatedSectors) trackEntropy.UniqueSectors = uniqueSectorsPerTrack.Count;
|
||||||
|
|
||||||
@@ -230,8 +229,7 @@ public sealed class Entropy
|
|||||||
EndProgressEvent?.Invoke();
|
EndProgressEvent?.Invoke();
|
||||||
|
|
||||||
entropy.Entropy += entTable.Select(l => l / (double)diskSize)
|
entropy.Entropy += entTable.Select(l => l / (double)diskSize)
|
||||||
.Select(static frequency => -(frequency * Math.Log(frequency, 2)))
|
.Sum(static frequency => -(frequency * Math.Log(frequency, 2)));
|
||||||
.Sum();
|
|
||||||
|
|
||||||
if(duplicatedSectors) entropy.UniqueSectors = uniqueSectors.Count;
|
if(duplicatedSectors) entropy.UniqueSectors = uniqueSectors.Count;
|
||||||
|
|
||||||
@@ -277,8 +275,7 @@ public sealed class Entropy
|
|||||||
EndProgressEvent?.Invoke();
|
EndProgressEvent?.Invoke();
|
||||||
|
|
||||||
entropy.Entropy += entTable.Select(l => l / (double)data.Length)
|
entropy.Entropy += entTable.Select(l => l / (double)data.Length)
|
||||||
.Select(static frequency => -(frequency * Math.Log(frequency, 2)))
|
.Sum(static frequency => -(frequency * Math.Log(frequency, 2)));
|
||||||
.Sum();
|
|
||||||
|
|
||||||
return entropy;
|
return entropy;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,7 +167,8 @@ public static class Partitions
|
|||||||
// Be sure that device partitions are not excluded if not mapped by any scheme...
|
// Be sure that device partitions are not excluded if not mapped by any scheme...
|
||||||
if(tapeImage is not null)
|
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)
|
if(tapeImage.Files != null)
|
||||||
{
|
{
|
||||||
@@ -183,7 +184,8 @@ public static class Partitions
|
|||||||
|
|
||||||
if(partitionableImage is not null)
|
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)
|
if(partitionableImage.Partitions != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
// ****************************************************************************/
|
// ****************************************************************************/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Collections.Generic;
|
||||||
using Aaru.CommonTypes.Enums;
|
using Aaru.CommonTypes.Enums;
|
||||||
using Aaru.CommonTypes.Interfaces;
|
using Aaru.CommonTypes.Interfaces;
|
||||||
using Aaru.Helpers;
|
using Aaru.Helpers;
|
||||||
@@ -53,7 +53,7 @@ public sealed partial class PascalPlugin
|
|||||||
if(!string.IsNullOrEmpty(path) && string.Compare(path, "/", StringComparison.OrdinalIgnoreCase) != 0)
|
if(!string.IsNullOrEmpty(path) && string.Compare(path, "/", StringComparison.OrdinalIgnoreCase) != 0)
|
||||||
return ErrorNumber.NotSupported;
|
return ErrorNumber.NotSupported;
|
||||||
|
|
||||||
var contents = _fileEntries.Select(ent => StringHandlers.PascalToString(ent.Filename, _encoding)).ToList();
|
List<string> contents = _fileEntries.ConvertAll(ent => StringHandlers.PascalToString(ent.Filename, _encoding));
|
||||||
|
|
||||||
if(_debug)
|
if(_debug)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -157,5 +157,5 @@ public sealed partial class A2R
|
|||||||
static bool IsCaptureTypeTiming(ulong resolution, byte[] buffer) =>
|
static bool IsCaptureTypeTiming(ulong resolution, byte[] buffer) =>
|
||||||
|
|
||||||
// TODO: This is only accurate for 300rpm
|
// TODO: This is only accurate for 300rpm
|
||||||
buffer.Select(static x => (int)x).Sum() * (long)resolution is > 230000000000 and < 270000000000;
|
buffer.Sum(static x => x) * (long)resolution is > 230000000000 and < 270000000000;
|
||||||
}
|
}
|
||||||
@@ -501,9 +501,8 @@ public sealed partial class Cdrdao
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(_writingTracks != null && _writingStreams != null)
|
if(_writingTracks != null && _writingStreams != null)
|
||||||
{
|
foreach(FileStream oldTrack in _writingStreams.Select(static t => t.Value).Distinct())
|
||||||
foreach(FileStream oldTrack in _writingStreams.Select(static t => t.Value).Distinct()) oldTrack.Close();
|
oldTrack.Close();
|
||||||
}
|
|
||||||
|
|
||||||
ulong currentOffset = 0;
|
ulong currentOffset = 0;
|
||||||
_writingTracks = [];
|
_writingTracks = [];
|
||||||
@@ -650,8 +649,8 @@ public sealed partial class Cdrdao
|
|||||||
(ulong)(track.RawBytesPerSector +
|
(ulong)(track.RawBytesPerSector +
|
||||||
(track.SubchannelType != TrackSubchannelType.None ? 96 : 0)));
|
(track.SubchannelType != TrackSubchannelType.None ? 96 : 0)));
|
||||||
|
|
||||||
foreach(KeyValuePair<ushort, int> index in track.Indexes.OrderBy(static i => i.Key)
|
foreach(KeyValuePair<ushort, int> index in track.Indexes.Where(static i => i.Key > 1)
|
||||||
.Where(static i => i.Key > 1))
|
.OrderBy(static i => i.Key))
|
||||||
{
|
{
|
||||||
msf = LbaToMsf((ulong)index.Value - (track.Pregap + track.StartSector));
|
msf = LbaToMsf((ulong)index.Value - (track.Pregap + track.StartSector));
|
||||||
|
|
||||||
|
|||||||
@@ -612,8 +612,8 @@ public sealed partial class CloneCd
|
|||||||
|
|
||||||
if(trackIndexes.TryGetValue((byte)tmpTrack.Sequence, out Dictionary<byte, int> indexes))
|
if(trackIndexes.TryGetValue((byte)tmpTrack.Sequence, out Dictionary<byte, int> indexes))
|
||||||
{
|
{
|
||||||
foreach((byte index, int value) in indexes.OrderBy(static i => i.Key)
|
foreach((byte index, int value) in indexes.Where(static trackIndex => trackIndex.Key > 1)
|
||||||
.Where(static trackIndex => trackIndex.Key > 1))
|
.OrderBy(static i => i.Key))
|
||||||
|
|
||||||
// Untested as of 20210711
|
// Untested as of 20210711
|
||||||
tmpTrack.Indexes[index] = value;
|
tmpTrack.Indexes[index] = value;
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ public abstract class OpticalImageConvertIssueTest
|
|||||||
|
|
||||||
foreach(SectorTagType tag in inputFormat.Info.ReadableSectorTags
|
foreach(SectorTagType tag in inputFormat.Info.ReadableSectorTags
|
||||||
.Where(static t => t == SectorTagType.CdTrackIsrc)
|
.Where(static t => t == SectorTagType.CdTrackIsrc)
|
||||||
.OrderBy(static t => t))
|
.Order())
|
||||||
{
|
{
|
||||||
foreach(Track track in tracks)
|
foreach(Track track in tracks)
|
||||||
{
|
{
|
||||||
@@ -267,7 +267,7 @@ public abstract class OpticalImageConvertIssueTest
|
|||||||
|
|
||||||
foreach(SectorTagType tag in inputFormat.Info.ReadableSectorTags
|
foreach(SectorTagType tag in inputFormat.Info.ReadableSectorTags
|
||||||
.Where(static t => t == SectorTagType.CdTrackFlags)
|
.Where(static t => t == SectorTagType.CdTrackFlags)
|
||||||
.OrderBy(static t => t))
|
.Order())
|
||||||
{
|
{
|
||||||
foreach(Track track in tracks)
|
foreach(Track track in tracks)
|
||||||
{
|
{
|
||||||
@@ -286,7 +286,7 @@ public abstract class OpticalImageConvertIssueTest
|
|||||||
subchannelExtents.Add((int)s);
|
subchannelExtents.Add((int)s);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(SectorTagType tag in inputFormat.Info.ReadableSectorTags.OrderBy(static t => t).TakeWhile(_ => UseLong))
|
foreach(SectorTagType tag in inputFormat.Info.ReadableSectorTags.Order().TakeWhile(_ => UseLong))
|
||||||
{
|
{
|
||||||
switch(tag)
|
switch(tag)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -342,7 +342,7 @@ public abstract class WritableOpticalMediaImageTest : BaseWritableMediaImageTest
|
|||||||
|
|
||||||
foreach(SectorTagType tag in inputFormat.Info.ReadableSectorTags
|
foreach(SectorTagType tag in inputFormat.Info.ReadableSectorTags
|
||||||
.Where(static t => t == SectorTagType.CdTrackIsrc)
|
.Where(static t => t == SectorTagType.CdTrackIsrc)
|
||||||
.OrderBy(static t => t))
|
.Order())
|
||||||
{
|
{
|
||||||
foreach(Track track in tracks)
|
foreach(Track track in tracks)
|
||||||
{
|
{
|
||||||
@@ -356,7 +356,7 @@ public abstract class WritableOpticalMediaImageTest : BaseWritableMediaImageTest
|
|||||||
|
|
||||||
foreach(SectorTagType tag in inputFormat.Info.ReadableSectorTags
|
foreach(SectorTagType tag in inputFormat.Info.ReadableSectorTags
|
||||||
.Where(static t => t == SectorTagType.CdTrackFlags)
|
.Where(static t => t == SectorTagType.CdTrackFlags)
|
||||||
.OrderBy(static t => t))
|
.Order())
|
||||||
{
|
{
|
||||||
foreach(Track track in tracks)
|
foreach(Track track in tracks)
|
||||||
{
|
{
|
||||||
@@ -375,8 +375,7 @@ public abstract class WritableOpticalMediaImageTest : BaseWritableMediaImageTest
|
|||||||
subchannelExtents.Add((int)s);
|
subchannelExtents.Add((int)s);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(SectorTagType tag in inputFormat.Info.ReadableSectorTags.OrderBy(static t => t)
|
foreach(SectorTagType tag in inputFormat.Info.ReadableSectorTags.Order().TakeWhile(_ => useLong))
|
||||||
.TakeWhile(_ => useLong))
|
|
||||||
{
|
{
|
||||||
switch(tag)
|
switch(tag)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -580,7 +580,7 @@ sealed class ConvertImageCommand : Command<ConvertImageCommand.Settings>
|
|||||||
|
|
||||||
foreach(SectorTagType tag in inputOptical.Info.ReadableSectorTags
|
foreach(SectorTagType tag in inputOptical.Info.ReadableSectorTags
|
||||||
.Where(static t => t == SectorTagType.CdTrackIsrc)
|
.Where(static t => t == SectorTagType.CdTrackIsrc)
|
||||||
.OrderBy(static t => t))
|
.Order())
|
||||||
{
|
{
|
||||||
foreach(Track track in tracks)
|
foreach(Track track in tracks)
|
||||||
{
|
{
|
||||||
@@ -594,7 +594,7 @@ sealed class ConvertImageCommand : Command<ConvertImageCommand.Settings>
|
|||||||
|
|
||||||
foreach(SectorTagType tag in inputOptical.Info.ReadableSectorTags
|
foreach(SectorTagType tag in inputOptical.Info.ReadableSectorTags
|
||||||
.Where(static t => t == SectorTagType.CdTrackFlags)
|
.Where(static t => t == SectorTagType.CdTrackFlags)
|
||||||
.OrderBy(static t => t))
|
.Order())
|
||||||
{
|
{
|
||||||
foreach(Track track in tracks)
|
foreach(Track track in tracks)
|
||||||
{
|
{
|
||||||
@@ -613,8 +613,7 @@ sealed class ConvertImageCommand : Command<ConvertImageCommand.Settings>
|
|||||||
subchannelExtents.Add((int)s);
|
subchannelExtents.Add((int)s);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(SectorTagType tag in inputOptical.Info.ReadableSectorTags.OrderBy(static t => t)
|
foreach(SectorTagType tag in inputOptical.Info.ReadableSectorTags.Order().TakeWhile(_ => useLong))
|
||||||
.TakeWhile(_ => useLong))
|
|
||||||
{
|
{
|
||||||
switch(tag)
|
switch(tag)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user