mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
[Refactor] Use static lambdas in LINQ queries for improved performance
This commit is contained in:
@@ -80,7 +80,7 @@ public sealed partial class DeviceReport
|
||||
|
||||
AaruLogging.WriteLine(Localization.Core.Sending_READ_FULL_TOC_to_the_device);
|
||||
|
||||
int retries = 0;
|
||||
var retries = 0;
|
||||
bool sense;
|
||||
byte[] buffer;
|
||||
ReadOnlySpan<byte> senseBuffer;
|
||||
@@ -127,7 +127,7 @@ public sealed partial class DeviceReport
|
||||
// Guaranteed to never fall into default
|
||||
FullTOC.CDFullTOC toc = decodedToc ?? default(FullTOC.CDFullTOC);
|
||||
|
||||
FullTOC.TrackDataDescriptor leadOutTrack = toc.TrackDescriptors.FirstOrDefault(t => t.POINT == 0xA2);
|
||||
FullTOC.TrackDataDescriptor leadOutTrack = toc.TrackDescriptors.FirstOrDefault(static t => t.POINT == 0xA2);
|
||||
|
||||
if(leadOutTrack.POINT != 0xA2)
|
||||
{
|
||||
@@ -139,8 +139,8 @@ public sealed partial class DeviceReport
|
||||
return;
|
||||
}
|
||||
|
||||
int min = 0, sec, frame;
|
||||
bool tocIsNotBcd = false;
|
||||
int min = 0, sec, frame;
|
||||
var tocIsNotBcd = false;
|
||||
|
||||
report.GdRomSwapDiscCapabilities.SwapDiscLeadOutPMIN = leadOutTrack.PMIN;
|
||||
report.GdRomSwapDiscCapabilities.SwapDiscLeadOutPSEC = leadOutTrack.PSEC;
|
||||
@@ -241,7 +241,7 @@ public sealed partial class DeviceReport
|
||||
// Guaranteed to never fall into default
|
||||
toc = decodedToc ?? default(FullTOC.CDFullTOC);
|
||||
|
||||
FullTOC.TrackDataDescriptor newLeadOutTrack = toc.TrackDescriptors.FirstOrDefault(t => t.POINT == 0xA2);
|
||||
FullTOC.TrackDataDescriptor newLeadOutTrack = toc.TrackDescriptors.FirstOrDefault(static t => t.POINT == 0xA2);
|
||||
|
||||
if(newLeadOutTrack.POINT != 0xA2)
|
||||
{
|
||||
@@ -1849,8 +1849,8 @@ public sealed partial class DeviceReport
|
||||
if(pressedKey.Key == ConsoleKey.N) return;
|
||||
|
||||
uint startingSector = 45000;
|
||||
bool readAsAudio = false;
|
||||
bool aborted = false;
|
||||
var readAsAudio = false;
|
||||
var aborted = false;
|
||||
MmcSubchannel subchannel = MmcSubchannel.None;
|
||||
uint blockSize = 2352;
|
||||
|
||||
@@ -1977,7 +1977,7 @@ public sealed partial class DeviceReport
|
||||
|
||||
byte[] lastSuccessfulPq = null;
|
||||
byte[] lastSuccessfulRw = null;
|
||||
bool trackModeChange = false;
|
||||
var trackModeChange = false;
|
||||
|
||||
AaruLogging.WriteLine();
|
||||
|
||||
|
||||
@@ -53,8 +53,8 @@ public sealed partial class DeviceReport
|
||||
|
||||
while(offset + 4 < response.Length)
|
||||
{
|
||||
ushort code = (ushort)((response[offset + 0] << 8) + response[offset + 1]);
|
||||
byte[] data = new byte[response[offset + 3] + 4];
|
||||
var code = (ushort)((response[offset + 0] << 8) + response[offset + 1]);
|
||||
var data = new byte[response[offset + 3] + 4];
|
||||
|
||||
if(code != 0x0108)
|
||||
{
|
||||
@@ -76,7 +76,7 @@ public sealed partial class DeviceReport
|
||||
/// <returns>MMC features report</returns>
|
||||
public MmcFeatures ReportMmcFeatures()
|
||||
{
|
||||
bool sense = true;
|
||||
var sense = true;
|
||||
byte[] buffer = [];
|
||||
|
||||
Spectre.ProgressSingleSpinner(ctx =>
|
||||
@@ -478,7 +478,7 @@ public sealed partial class DeviceReport
|
||||
|
||||
if(ftr010C.HasValue)
|
||||
{
|
||||
byte[] temp = new byte[4];
|
||||
var temp = new byte[4];
|
||||
temp[0] = (byte)((ftr010C.Value.Century & 0xFF00) >> 8);
|
||||
temp[1] = (byte)(ftr010C.Value.Century & 0xFF);
|
||||
temp[2] = (byte)((ftr010C.Value.Year & 0xFF00) >> 8);
|
||||
@@ -578,7 +578,7 @@ public sealed partial class DeviceReport
|
||||
public TestedMedia ReportMmcMedia(string mediaType, bool tryPlextor, bool tryPioneer, bool tryNec, bool tryHldtst,
|
||||
bool tryMediaTekF106, bool tryLiteOn)
|
||||
{
|
||||
bool sense = true;
|
||||
var sense = true;
|
||||
byte[] buffer = [];
|
||||
ReadOnlySpan<byte> senseBuffer = [];
|
||||
var mediaTest = new TestedMedia();
|
||||
@@ -609,7 +609,7 @@ public sealed partial class DeviceReport
|
||||
if(!sense && !_dev.Error)
|
||||
{
|
||||
mediaTest.SupportsReadCapacity16 = true;
|
||||
byte[] temp = new byte[8];
|
||||
var temp = new byte[8];
|
||||
Array.Copy(buffer, 0, temp, 0, 8);
|
||||
Array.Reverse(temp);
|
||||
mediaTest.Blocks = BitConverter.ToUInt64(temp, 0) + 1;
|
||||
@@ -2749,8 +2749,8 @@ public sealed partial class DeviceReport
|
||||
|
||||
if(tryMediaTekF106)
|
||||
{
|
||||
bool triedLba0 = false;
|
||||
bool triedLeadOut = false;
|
||||
var triedLba0 = false;
|
||||
var triedLeadOut = false;
|
||||
|
||||
Spectre.ProgressSingleSpinner(ctx =>
|
||||
{
|
||||
@@ -3036,7 +3036,7 @@ public sealed partial class DeviceReport
|
||||
{
|
||||
FullTOC.CDFullTOC decodedToc = decodedTocNullable.Value;
|
||||
|
||||
if(!decodedToc.TrackDescriptors.Any(t => t.SessionNumber > 1))
|
||||
if(!decodedToc.TrackDescriptors.Any(static t => t.SessionNumber > 1))
|
||||
{
|
||||
AaruLogging.Error(Localization.Core
|
||||
.Could_not_find_second_session_Have_you_inserted_the_correct_type_of_disc);
|
||||
@@ -3045,10 +3045,13 @@ public sealed partial class DeviceReport
|
||||
}
|
||||
|
||||
FullTOC.TrackDataDescriptor firstSessionLeadOutTrack =
|
||||
decodedToc.TrackDescriptors.FirstOrDefault(t => t is { SessionNumber: 1, POINT: 0xA2 });
|
||||
decodedToc.TrackDescriptors.FirstOrDefault(static t => t is { SessionNumber: 1, POINT: 0xA2 });
|
||||
|
||||
FullTOC.TrackDataDescriptor secondSessionFirstTrack =
|
||||
decodedToc.TrackDescriptors.FirstOrDefault(t => t is { SessionNumber: > 1, POINT: <= 99 });
|
||||
decodedToc.TrackDescriptors.FirstOrDefault(static t => t is
|
||||
{
|
||||
SessionNumber: > 1, POINT: <= 99
|
||||
});
|
||||
|
||||
if(firstSessionLeadOutTrack.SessionNumber == 0 || secondSessionFirstTrack.SessionNumber == 0)
|
||||
{
|
||||
@@ -3071,16 +3074,16 @@ public sealed partial class DeviceReport
|
||||
secondSessionFirstTrack.PFRAME);
|
||||
|
||||
// Skip Lead-Out pre-gap
|
||||
uint firstSessionLeadOutLba = (uint)(firstSessionLeadOutTrack.PMIN * 60 * 75 +
|
||||
firstSessionLeadOutTrack.PSEC * 75 +
|
||||
firstSessionLeadOutTrack.PFRAME +
|
||||
150);
|
||||
var firstSessionLeadOutLba = (uint)(firstSessionLeadOutTrack.PMIN * 60 * 75 +
|
||||
firstSessionLeadOutTrack.PSEC * 75 +
|
||||
firstSessionLeadOutTrack.PFRAME +
|
||||
150);
|
||||
|
||||
// Skip second session track pre-gap
|
||||
uint secondSessionLeadInLba = (uint)(secondSessionFirstTrack.PMIN * 60 * 75 +
|
||||
secondSessionFirstTrack.PSEC * 75 +
|
||||
secondSessionFirstTrack.PFRAME -
|
||||
300);
|
||||
var secondSessionLeadInLba = (uint)(secondSessionFirstTrack.PMIN * 60 * 75 +
|
||||
secondSessionFirstTrack.PSEC * 75 +
|
||||
secondSessionFirstTrack.PFRAME -
|
||||
300);
|
||||
|
||||
Spectre.ProgressSingleSpinner(ctx =>
|
||||
{
|
||||
|
||||
@@ -50,7 +50,7 @@ public sealed partial class DeviceReport
|
||||
/// <returns>SCSI report</returns>
|
||||
public Scsi ReportScsiInquiry()
|
||||
{
|
||||
bool sense = true;
|
||||
var sense = true;
|
||||
byte[] buffer = [];
|
||||
|
||||
Spectre.ProgressSingleSpinner(ctx =>
|
||||
@@ -85,7 +85,7 @@ public sealed partial class DeviceReport
|
||||
return inquiry;
|
||||
|
||||
// Clear Seagate serial number
|
||||
for(int i = 36; i <= 43; i++) inquiry[i] = 0;
|
||||
for(var i = 36; i <= 43; i++) inquiry[i] = 0;
|
||||
|
||||
return inquiry;
|
||||
}
|
||||
@@ -95,7 +95,7 @@ public sealed partial class DeviceReport
|
||||
/// <returns>List of decoded SCSI EVPD pages</returns>
|
||||
public List<ScsiPage> ReportEvpdPages(string vendor)
|
||||
{
|
||||
bool sense = false;
|
||||
var sense = false;
|
||||
byte[] buffer = [];
|
||||
|
||||
Spectre.ProgressSingleSpinner(ctx =>
|
||||
@@ -115,10 +115,10 @@ public sealed partial class DeviceReport
|
||||
Spectre.ProgressSingleSpinner(ctx =>
|
||||
{
|
||||
ProgressTask task = ctx.AddTask(Localization.Core.Querying_SCSI_EVPD_pages,
|
||||
maxValue: evpdPages.Count(page => page != 0x80))
|
||||
maxValue: evpdPages.Count(static page => page != 0x80))
|
||||
.IsIndeterminate();
|
||||
|
||||
foreach(byte page in evpdPages.Where(page => page != 0x80))
|
||||
foreach(byte page in evpdPages.Where(static page => page != 0x80))
|
||||
{
|
||||
task.Description = string.Format(Localization.Core.Querying_SCSI_EVPD_0, page);
|
||||
task.Increment(1);
|
||||
@@ -135,7 +135,7 @@ public sealed partial class DeviceReport
|
||||
|
||||
break;
|
||||
case 0x80:
|
||||
byte[] identify = new byte[512];
|
||||
var identify = new byte[512];
|
||||
Array.Copy(buffer, 60, identify, 0, 512);
|
||||
identify = ClearIdentify(identify);
|
||||
Array.Copy(identify, 0, buffer, 60, 512);
|
||||
@@ -184,7 +184,7 @@ public sealed partial class DeviceReport
|
||||
|
||||
if(pageResponse.Length < 6) return null;
|
||||
|
||||
int position = 4;
|
||||
var position = 4;
|
||||
|
||||
while(position < pageResponse.Length)
|
||||
{
|
||||
@@ -192,7 +192,7 @@ public sealed partial class DeviceReport
|
||||
|
||||
if(length + position + 4 >= pageResponse.Length) length = (byte)(pageResponse.Length - position - 4);
|
||||
|
||||
byte[] empty = new byte[length];
|
||||
var empty = new byte[length];
|
||||
Array.Copy(empty, 0, pageResponse, position + 4, length);
|
||||
|
||||
position += 4 + length;
|
||||
@@ -226,7 +226,7 @@ public sealed partial class DeviceReport
|
||||
ScsiModeSensePageControl.Changeable
|
||||
})
|
||||
{
|
||||
bool saveBuffer = false;
|
||||
var saveBuffer = false;
|
||||
|
||||
sense = _dev.ModeSense10(out byte[] mode10Buffer,
|
||||
out _,
|
||||
@@ -335,7 +335,7 @@ public sealed partial class DeviceReport
|
||||
ScsiModeSensePageControl.Changeable
|
||||
})
|
||||
{
|
||||
bool saveBuffer = false;
|
||||
var saveBuffer = false;
|
||||
|
||||
sense = _dev.ModeSense6(out byte[] mode6Buffer,
|
||||
out _,
|
||||
@@ -511,7 +511,7 @@ public sealed partial class DeviceReport
|
||||
public TestedMedia ReportScsiMedia()
|
||||
{
|
||||
var mediaTest = new TestedMedia();
|
||||
bool sense = true;
|
||||
var sense = true;
|
||||
byte[] buffer = [];
|
||||
ReadOnlySpan<byte> senseBuffer = [];
|
||||
|
||||
@@ -541,7 +541,7 @@ public sealed partial class DeviceReport
|
||||
if(!sense && !_dev.Error)
|
||||
{
|
||||
mediaTest.SupportsReadCapacity16 = true;
|
||||
byte[] temp = new byte[8];
|
||||
var temp = new byte[8];
|
||||
Array.Copy(buffer, 0, temp, 0, 8);
|
||||
Array.Reverse(temp);
|
||||
mediaTest.Blocks = BitConverter.ToUInt64(temp, 0) + 1;
|
||||
@@ -886,7 +886,7 @@ public sealed partial class DeviceReport
|
||||
/// <returns>Media report</returns>
|
||||
public TestedMedia ReportScsi()
|
||||
{
|
||||
bool sense = true;
|
||||
var sense = true;
|
||||
byte[] buffer = [];
|
||||
ReadOnlySpan<byte> senseBuffer = [];
|
||||
|
||||
@@ -921,7 +921,7 @@ public sealed partial class DeviceReport
|
||||
if(!sense && !_dev.Error)
|
||||
{
|
||||
capabilities.SupportsReadCapacity16 = true;
|
||||
byte[] temp = new byte[8];
|
||||
var temp = new byte[8];
|
||||
Array.Copy(buffer, 0, temp, 0, 8);
|
||||
Array.Reverse(temp);
|
||||
capabilities.Blocks = BitConverter.ToUInt64(temp, 0) + 1;
|
||||
|
||||
Reference in New Issue
Block a user