Optimized memory usage

This commit is contained in:
Samuele Lorefice
2025-02-20 21:20:10 +01:00
parent f383debd18
commit 9a0024884c

View File

@@ -120,8 +120,8 @@ public class Reader {
/// <returns></returns> /// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private long GetFieldDataOffset(int fieldIndex, FieldInfo[] fieldMetadata) => private long GetFieldDataOffset(int fieldIndex, FieldInfo[] fieldMetadata) =>
fieldMetadata.Where(f => f.GetCustomAttribute<DNAFieldAttribute>()!.OriginalIndex < fieldIndex) fieldMetadata.First(x => x.GetCustomAttribute<DNAFieldAttribute>()!.OriginalIndex == fieldIndex)
.Sum(f => f.GetCustomAttribute<DNAFieldAttribute>()!.Size); .GetCustomAttribute<DNAFieldAttribute>()!.MemoryOffset;
/// <summary> /// <summary>
/// Creates an instance of a given type /// Creates an instance of a given type
@@ -147,7 +147,7 @@ public class Reader {
//Calculate the offset from where the data of the field starts. //Calculate the offset from where the data of the field starts.
//Because the order of the fields is not guaranteed we need to compute it each time //Because the order of the fields is not guaranteed we need to compute it each time
long offset = GetFieldDataOffset(attrib.OriginalIndex, fieldMetadata); long offset = attrib.MemoryOffset;
int size = attrib.Size; int size = attrib.Size;
var data = new byte[size]; var data = new byte[size];