[Refactor] Use static lambdas in LINQ queries for improved performance

This commit is contained in:
2025-11-24 03:00:06 +00:00
parent 5fe7f574d6
commit 04c45e69fa
126 changed files with 971 additions and 929 deletions

View File

@@ -67,7 +67,7 @@ public sealed partial class AppleDOS
// Read the catalog sector
CatalogSector catSector = Marshal.ByteArrayToStructureLittleEndian<CatalogSector>(catSectorB);
foreach(FileEntry entry in catSector.entries.Where(entry => entry.extentTrack > 0))
foreach(FileEntry entry in catSector.entries.Where(static entry => entry.extentTrack > 0))
{
_track1UsedByFiles |= entry.extentTrack == 1;
_track2UsedByFiles |= entry.extentTrack == 2;

View File

@@ -119,7 +119,8 @@ public sealed partial class AppleDOS
_fileCache = new Dictionary<string, byte[]>();
_extentCache = new Dictionary<string, byte[]>();
foreach(ErrorNumber error in _catalogCache.Keys.Select(CacheFile).Where(error => error != ErrorNumber.NoError))
foreach(ErrorNumber error in _catalogCache.Keys.Select(CacheFile)
.Where(static error => error != ErrorNumber.NoError))
return error;
uint tracksOnBoot = 1;

View File

@@ -58,8 +58,7 @@ public sealed partial class AppleMFS
entry.flTyp = _directoryBlocks[offset + 1];
entry.flUsrWds =
Marshal.ByteArrayToStructureBigEndian<AppleCommon.FInfo>(_directoryBlocks, offset + 2, 16);
entry.flUsrWds = Marshal.ByteArrayToStructureBigEndian<AppleCommon.FInfo>(_directoryBlocks, offset + 2, 16);
entry.flFlNum = BigEndianBitConverter.ToUInt32(_directoryBlocks, offset + 18);
entry.flStBlk = BigEndianBitConverter.ToUInt16(_directoryBlocks, offset + 22);
@@ -132,7 +131,7 @@ public sealed partial class AppleMFS
if(!string.IsNullOrEmpty(path) && string.Compare(path, "/", StringComparison.OrdinalIgnoreCase) != 0)
return ErrorNumber.NotSupported;
var contents = _idToFilename.Select(kvp => kvp.Value).ToList();
var contents = _idToFilename.Select(static kvp => kvp.Value).ToList();
if(_debug)
{

View File

@@ -308,7 +308,7 @@ public sealed partial class FAT
// Check OS/2 .LONGNAME
if(_eaCache != null && _namespace is Namespace.Os2 or Namespace.Ecs && !_fat32)
{
var filesWithEas = currentDirectory.Where(t => t.Value.Dirent.ea_handle != 0).ToList();
var filesWithEas = currentDirectory.Where(static t => t.Value.Dirent.ea_handle != 0).ToList();
foreach(KeyValuePair<string, CompleteDirectoryEntry> fileWithEa in filesWithEas)
{

View File

@@ -194,9 +194,8 @@ public sealed partial class FAT
};
if((fat32Bpb.flags & 0xF8) == 0x00)
{
if((fat32Bpb.flags & 0x01) == 0x01) Metadata.Dirty = true;
}
if((fat32Bpb.flags & 0x01) == 0x01)
Metadata.Dirty = true;
if((fat32Bpb.mirror_flags & 0x80) == 0x80) _useFirstFat = (fat32Bpb.mirror_flags & 0xF) != 1;
@@ -461,9 +460,8 @@ public sealed partial class FAT
if(fakeBpb.signature is 0x28 or 0x29 || andosOemCorrect)
{
if((fakeBpb.flags & 0xF8) == 0x00)
{
if((fakeBpb.flags & 0x01) == 0x01) Metadata.Dirty = true;
}
if((fakeBpb.flags & 0x01) == 0x01)
Metadata.Dirty = true;
if(fakeBpb.signature == 0x29 || andosOemCorrect)
{
@@ -884,7 +882,7 @@ public sealed partial class FAT
// Check OS/2 .LONGNAME
if(_eaCache != null && _namespace is Namespace.Os2 or Namespace.Ecs && !_fat32)
{
var rootFilesWithEas = _rootDirectoryCache.Where(t => t.Value.Dirent.ea_handle != 0).ToList();
var rootFilesWithEas = _rootDirectoryCache.Where(static t => t.Value.Dirent.ea_handle != 0).ToList();
foreach(KeyValuePair<string, CompleteDirectoryEntry> fileWithEa in rootFilesWithEas)
{

View File

@@ -55,9 +55,7 @@ public sealed partial class ISO9660
while(entryOff + _cdiDirectoryRecordSize < data.Length)
{
CdiDirectoryRecord record =
Marshal.ByteArrayToStructureBigEndian<CdiDirectoryRecord>(data,
entryOff,
_cdiDirectoryRecordSize);
Marshal.ByteArrayToStructureBigEndian<CdiDirectoryRecord>(data, entryOff, _cdiDirectoryRecordSize);
if(record.length == 0)
{
@@ -107,9 +105,7 @@ public sealed partial class ISO9660
if(systemAreaStart % 2 != 0) systemAreaStart++;
entry.CdiSystemArea =
Marshal.ByteArrayToStructureBigEndian<CdiSystemArea>(data,
systemAreaStart,
_cdiSystemAreaSize);
Marshal.ByteArrayToStructureBigEndian<CdiSystemArea>(data, systemAreaStart, _cdiSystemAreaSize);
if(entry.CdiSystemArea.Value.attributes.HasFlag(CdiAttributes.Directory))
entry.Flags |= FileFlags.Directory;
@@ -352,18 +348,19 @@ public sealed partial class ISO9660
// Relocated directories should be shown in correct place when using Rock Ridge namespace
return _namespace == Namespace.Rrip
? entries.Where(e => !e.Value.RockRidgeRelocated).ToDictionary(x => x.Key, x => x.Value)
? entries.Where(static e => !e.Value.RockRidgeRelocated)
.ToDictionary(static x => x.Key, static x => x.Value)
: entries;
}
void DecodeTransTable(Dictionary<string, DecodedDirectoryEntry> entries)
{
KeyValuePair<string, DecodedDirectoryEntry> transTblEntry =
entries.FirstOrDefault(e => !e.Value.Flags.HasFlag(FileFlags.Directory) &&
(e.Value.Filename.Equals("trans.tbl",
StringComparison.CurrentCultureIgnoreCase) ||
e.Value.Filename.Equals("trans.tbl;1",
StringComparison.CurrentCultureIgnoreCase)));
entries.FirstOrDefault(static e => !e.Value.Flags.HasFlag(FileFlags.Directory) &&
(e.Value.Filename.Equals("trans.tbl",
StringComparison.CurrentCultureIgnoreCase) ||
e.Value.Filename.Equals("trans.tbl;1",
StringComparison.CurrentCultureIgnoreCase)));
if(transTblEntry.Value == null) return;
@@ -568,8 +565,8 @@ public sealed partial class ISO9660
break;
case XA_MAGIC:
entry.XA = Marshal.ByteArrayToStructureBigEndian<CdromXa>(data,
systemAreaOff,
Marshal.SizeOf<CdromXa>());
systemAreaOff,
Marshal.SizeOf<CdromXa>());
systemAreaOff += Marshal.SizeOf<CdromXa>();
@@ -580,8 +577,8 @@ public sealed partial class ISO9660
case AMIGA_MAGIC:
AmigaEntry amiga =
Marshal.ByteArrayToStructureBigEndian<AmigaEntry>(data,
systemAreaOff,
Marshal.SizeOf<AmigaEntry>());
systemAreaOff,
Marshal.SizeOf<AmigaEntry>());
var protectionLength = 0;
@@ -996,8 +993,8 @@ public sealed partial class ISO9660
CdiDirectoryRecord record =
Marshal.ByteArrayToStructureBigEndian<CdiDirectoryRecord>(sector,
tEntry.XattrLength,
_cdiDirectoryRecordSize);
tEntry.XattrLength,
_cdiDirectoryRecordSize);
if(record.length == 0) break;
@@ -1020,9 +1017,7 @@ public sealed partial class ISO9660
if(systemAreaStart % 2 != 0) systemAreaStart++;
entry.CdiSystemArea =
Marshal.ByteArrayToStructureBigEndian<CdiSystemArea>(sector,
systemAreaStart,
_cdiSystemAreaSize);
Marshal.ByteArrayToStructureBigEndian<CdiSystemArea>(sector, systemAreaStart, _cdiSystemAreaSize);
if(entry.CdiSystemArea.Value.attributes.HasFlag(CdiAttributes.Directory))
entry.Flags |= FileFlags.Directory;