From 9a0024884cf64ca5dd9a68bc4b1d9920b1dbbd81 Mon Sep 17 00:00:00 2001 From: Samuele Lorefice Date: Thu, 20 Feb 2025 21:20:10 +0100 Subject: [PATCH] Optimized memory usage --- BlendFile/Reader.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/BlendFile/Reader.cs b/BlendFile/Reader.cs index a227578..677e2eb 100644 --- a/BlendFile/Reader.cs +++ b/BlendFile/Reader.cs @@ -120,8 +120,8 @@ public class Reader { /// [MethodImpl(MethodImplOptions.AggressiveInlining)] private long GetFieldDataOffset(int fieldIndex, FieldInfo[] fieldMetadata) => - fieldMetadata.Where(f => f.GetCustomAttribute()!.OriginalIndex < fieldIndex) - .Sum(f => f.GetCustomAttribute()!.Size); + fieldMetadata.First(x => x.GetCustomAttribute()!.OriginalIndex == fieldIndex) + .GetCustomAttribute()!.MemoryOffset; /// /// 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. //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; var data = new byte[size];