From 99876cea2ad5c93b794b71edbd8a47cb6a947d9b Mon Sep 17 00:00:00 2001 From: Crsky Date: Mon, 23 Mar 2026 23:32:38 +0800 Subject: [PATCH] perf: Improve LittleEndian --- GameRes/Utility.cs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/GameRes/Utility.cs b/GameRes/Utility.cs index 58ed7908..701f7d4f 100644 --- a/GameRes/Utility.cs +++ b/GameRes/Utility.cs @@ -292,6 +292,42 @@ namespace GameRes.Utility return (long)ToUInt64 (value, index); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ushort ToUInt16 (byte[] value, int index) + { + return (ushort)(value[index] | value[index+1] << 8); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static short ToInt16 (byte[] value, int index) + { + return (short)(value[index] | value[index+1] << 8); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static uint ToUInt32 (byte[] value, int index) + { + return (uint)(value[index] | value[index+1] << 8 | value[index+2] << 16 | value[index+3] << 24); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static int ToInt32 (byte[] value, int index) + { + return (int)ToUInt32 (value, index); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static ulong ToUInt64 (byte[] value, int index) + { + return (ulong)ToUInt32 (value, index) | ((ulong)ToUInt32 (value, index+4) << 32); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static long ToInt64 (byte[] value, int index) + { + return (long)ToUInt64 (value, index); + } + public static void Pack (ushort value, byte[] buf, int index) { buf[index] = (byte)(value);