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:
@@ -12,6 +12,11 @@ namespace Aaru.Archives;
|
||||
|
||||
public sealed partial class Stfs
|
||||
{
|
||||
static void ReverseShorts(byte[] shorts, int start, int count)
|
||||
{
|
||||
for(int i = start; i < start + count; i += 2) (shorts[i], shorts[i + 1]) = (shorts[i + 1], shorts[i]);
|
||||
}
|
||||
|
||||
#region IArchive Members
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -22,7 +27,7 @@ public sealed partial class Stfs
|
||||
Stream stream = filter.GetDataForkStream();
|
||||
stream.Position = 0;
|
||||
|
||||
byte[] hdr = new byte[Marshal.SizeOf<RemotePackage>()];
|
||||
var hdr = new byte[Marshal.SizeOf<RemotePackage>()];
|
||||
|
||||
stream.ReadExactly(hdr, 0, hdr.Length);
|
||||
|
||||
@@ -44,7 +49,7 @@ public sealed partial class Stfs
|
||||
Stream stream = filter.GetDataForkStream();
|
||||
stream.Position = 0;
|
||||
|
||||
byte[] hdr = new byte[Marshal.SizeOf<RemotePackage>()];
|
||||
var hdr = new byte[Marshal.SizeOf<RemotePackage>()];
|
||||
|
||||
stream.ReadExactly(hdr, 0, hdr.Length);
|
||||
|
||||
@@ -133,35 +138,36 @@ public sealed partial class Stfs
|
||||
sb.AppendFormat(Localization.Descriptor_type_0, header.Metadata.DescriptorType).AppendLine();
|
||||
|
||||
foreach(LocalizedString displayName in
|
||||
header.Metadata.DisplayName.Where(displayName => displayName.Name is not ""))
|
||||
header.Metadata.DisplayName.Where(static displayName => displayName.Name is not ""))
|
||||
sb.AppendFormat(Localization.Display_name_0, Markup.Escape(displayName.Name)).AppendLine();
|
||||
|
||||
foreach(LocalizedString description in
|
||||
header.Metadata.DisplayDescription.Where(description => description.Name is not ""))
|
||||
header.Metadata.DisplayDescription.Where(static description => description.Name is not ""))
|
||||
sb.AppendFormat(Localization.Display_description_0, Markup.Escape(description.Name)).AppendLine();
|
||||
|
||||
if(header.Metadata.DeviceId.Any(c => c != 0x00))
|
||||
if(header.Metadata.DeviceId.Any(static c => c != 0x00))
|
||||
{
|
||||
sb.AppendFormat(Localization.Device_ID_0,
|
||||
StringHandlers.CToString(header.Metadata.DeviceId, Encoding.ASCII).Trim())
|
||||
.AppendLine();
|
||||
}
|
||||
|
||||
if(header.Metadata.ConsoleId.Any(c => c != 0x00))
|
||||
if(header.Metadata.ConsoleId.Any(static c => c != 0x00))
|
||||
{
|
||||
sb.AppendFormat(Localization.Console_ID_0,
|
||||
BitConverter.ToString(header.Metadata.ConsoleId).Replace("-", ""))
|
||||
.AppendLine();
|
||||
}
|
||||
|
||||
if(header.Metadata.ProfileId.Any(c => c != 0x00))
|
||||
if(header.Metadata.ProfileId.Any(static c => c != 0x00))
|
||||
{
|
||||
sb.AppendFormat(Localization.Profile_ID_0,
|
||||
BitConverter.ToString(header.Metadata.ProfileId).Replace("-", ""))
|
||||
.AppendLine();
|
||||
}
|
||||
|
||||
information = sb.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
static void ReverseShorts(byte[] shorts, int start, int count)
|
||||
{
|
||||
for(int i = start; i < start + count; i += 2) (shorts[i], shorts[i + 1]) = (shorts[i + 1], shorts[i]);
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public sealed partial class Symbian
|
||||
|
||||
Stream stream = filter.GetDataForkStream();
|
||||
|
||||
byte[] hdr = new byte[Marshal.SizeOf<SymbianHeader>()];
|
||||
var hdr = new byte[Marshal.SizeOf<SymbianHeader>()];
|
||||
|
||||
stream.EnsureRead(hdr, 0, hdr.Length);
|
||||
|
||||
@@ -78,7 +78,7 @@ public sealed partial class Symbian
|
||||
|
||||
if(stream.Length < Marshal.SizeOf<SymbianHeader>()) return;
|
||||
|
||||
byte[] buffer = new byte[Marshal.SizeOf<SymbianHeader>()];
|
||||
var buffer = new byte[Marshal.SizeOf<SymbianHeader>()];
|
||||
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
stream.EnsureRead(buffer, 0, buffer.Length);
|
||||
@@ -164,7 +164,7 @@ public sealed partial class Symbian
|
||||
|
||||
// Go to enumerate languages
|
||||
br.BaseStream.Seek(sh.lang_ptr, SeekOrigin.Begin);
|
||||
for(int i = 0; i < sh.languages; i++) languages.Add(((LanguageCodes)br.ReadUInt16()).ToString("G"));
|
||||
for(var i = 0; i < sh.languages; i++) languages.Add(((LanguageCodes)br.ReadUInt16()).ToString("G"));
|
||||
|
||||
// Go to component record
|
||||
br.BaseStream.Seek(sh.comp_ptr, SeekOrigin.Begin);
|
||||
@@ -186,7 +186,7 @@ public sealed partial class Symbian
|
||||
span = buffer;
|
||||
componentRecord.namesPointers = MemoryMarshal.Cast<byte, uint>(span)[..languages.Count].ToArray();
|
||||
|
||||
for(int i = 0; i < sh.languages; i++)
|
||||
for(var i = 0; i < sh.languages; i++)
|
||||
{
|
||||
AaruLogging.Debug(MODULE_NAME,
|
||||
Localization.Found_component_name_for_language_0_at_1_with_a_length_of_2_bytes,
|
||||
@@ -202,7 +202,7 @@ public sealed partial class Symbian
|
||||
// Go to capabilities (???)
|
||||
br.BaseStream.Seek(sh.caps_ptr, SeekOrigin.Begin);
|
||||
|
||||
for(int i = 0; i < sh.capabilities; i++)
|
||||
for(var i = 0; i < sh.capabilities; i++)
|
||||
{
|
||||
uint cap_Key = br.ReadUInt32();
|
||||
uint cap_Value = br.ReadUInt32();
|
||||
@@ -228,7 +228,7 @@ public sealed partial class Symbian
|
||||
|
||||
description.AppendFormat(Localization.File_contains_0_languages, sh.languages).AppendLine();
|
||||
|
||||
for(int i = 0; i < languages.Count; i++)
|
||||
for(var i = 0; i < languages.Count; i++)
|
||||
{
|
||||
if(i > 0) description.Append(", ");
|
||||
description.Append($"[italic][rosybrown]{languages[i]}[/][/]");
|
||||
@@ -237,7 +237,7 @@ public sealed partial class Symbian
|
||||
description.AppendLine();
|
||||
description.AppendLine();
|
||||
|
||||
for(int i = 0; i < languages.Count; i++)
|
||||
for(var i = 0; i < languages.Count; i++)
|
||||
{
|
||||
description.AppendFormat(Localization.Component_name_for_language_with_code_0_1,
|
||||
languages[i],
|
||||
@@ -254,7 +254,7 @@ public sealed partial class Symbian
|
||||
|
||||
if(sh.requisites > 0)
|
||||
{
|
||||
for(int r = 0; r < sh.requisites; r++)
|
||||
for(var r = 0; r < sh.requisites; r++)
|
||||
{
|
||||
br.BaseStream.Seek(offset, SeekOrigin.Begin);
|
||||
|
||||
@@ -286,7 +286,7 @@ public sealed partial class Symbian
|
||||
|
||||
offset = (uint)br.BaseStream.Position;
|
||||
|
||||
for(int i = 0; i < languages.Count; i++)
|
||||
for(var i = 0; i < languages.Count; i++)
|
||||
{
|
||||
br.BaseStream.Seek(requisiteRecord.namesPointers[i], SeekOrigin.Begin);
|
||||
buffer = br.ReadBytes((int)requisiteRecord.namesLengths[i]);
|
||||
@@ -311,7 +311,7 @@ public sealed partial class Symbian
|
||||
|
||||
uint currentFile = 0;
|
||||
offset = sh.files_ptr;
|
||||
int conditionLevel = 0;
|
||||
var conditionLevel = 0;
|
||||
_options = [];
|
||||
|
||||
// Get only the options records
|
||||
@@ -338,11 +338,11 @@ public sealed partial class Symbian
|
||||
// Conditions do as well
|
||||
_conditions.Reverse();
|
||||
|
||||
if(_files.Any(t => t.language is null))
|
||||
if(_files.Any(static t => t.language is null))
|
||||
{
|
||||
description.AppendLine(Localization.Files_for_all_languages);
|
||||
|
||||
foreach(DecodedFileRecord file in _files.Where(t => t.language is null))
|
||||
foreach(DecodedFileRecord file in _files.Where(static t => t.language is null))
|
||||
description.AppendLine($"[green]{Markup.Escape(file.destinationName)}[/]");
|
||||
|
||||
description.AppendLine();
|
||||
@@ -362,7 +362,7 @@ public sealed partial class Symbian
|
||||
|
||||
if(_options.Count > 0)
|
||||
{
|
||||
for(int i = 0; i < _options.Count; i++)
|
||||
for(var i = 0; i < _options.Count; i++)
|
||||
{
|
||||
OptionRecord option = _options[i];
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public sealed partial class Symbian
|
||||
|
||||
if(_stream.Length < Marshal.SizeOf<SymbianHeader>()) return ErrorNumber.InvalidArgument;
|
||||
|
||||
byte[] buffer = new byte[Marshal.SizeOf<SymbianHeader>()];
|
||||
var buffer = new byte[Marshal.SizeOf<SymbianHeader>()];
|
||||
|
||||
_stream.Seek(0, SeekOrigin.Begin);
|
||||
_stream.EnsureRead(buffer, 0, buffer.Length);
|
||||
@@ -123,7 +123,7 @@ public sealed partial class Symbian
|
||||
|
||||
// Go to enumerate languages
|
||||
br.BaseStream.Seek(sh.lang_ptr, SeekOrigin.Begin);
|
||||
for(int i = 0; i < sh.languages; i++) languages.Add(((LanguageCodes)br.ReadUInt16()).ToString("G"));
|
||||
for(var i = 0; i < sh.languages; i++) languages.Add(((LanguageCodes)br.ReadUInt16()).ToString("G"));
|
||||
|
||||
_files = [];
|
||||
_conditions = [];
|
||||
@@ -131,7 +131,7 @@ public sealed partial class Symbian
|
||||
|
||||
uint currentFile = 0;
|
||||
uint offset = sh.files_ptr;
|
||||
int conditionLevel = 0;
|
||||
var conditionLevel = 0;
|
||||
|
||||
// Get only the options records
|
||||
do
|
||||
@@ -178,7 +178,7 @@ public sealed partial class Symbian
|
||||
_compressed = true;
|
||||
}
|
||||
|
||||
if(_files.Any(t => t.mime is not null)) _features |= ArchiveSupportedFeature.SupportsXAttrs;
|
||||
if(_files.Any(static t => t.mime is not null)) _features |= ArchiveSupportedFeature.SupportsXAttrs;
|
||||
|
||||
Opened = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user