[*] Micro-optimize auTypeUtils

This commit is contained in:
Reece Wilson 2022-03-11 04:07:02 +00:00
parent 7bfcce52fd
commit 0d969c3560

View File

@ -14,31 +14,35 @@
template<typename T> template<typename T>
static auline T AuReadGenericLE(const void *ptr, int offset) static auline T AuReadGenericLE(const void *ptr, int offset)
{ {
#if defined(AURORA_PERMIT_ARBITRARY_REF) && defined(AU_CPU_ENDIAN_LITTLE) #if defined(AURORA_PERMIT_ARBITRARY_REF)
return *reinterpret_cast<const T *>(reinterpret_cast<const AuUInt8 *>(ptr) + offset); T temp = *reinterpret_cast<const T *>(reinterpret_cast<const AuUInt8 *>(ptr) + offset);
#else #else
T temp; T temp;
AuMemcpy(&temp, reinterpret_cast<const AuUInt8 *>(ptr) + offset, sizeof(temp)); AuMemcpy(&temp, reinterpret_cast<const AuUInt8 *>(ptr) + offset, sizeof(temp));
#endif
#if !defined(AU_CPU_ENDIAN_LITTLE) #if !defined(AU_CPU_ENDIAN_LITTLE)
temp = AuFlipEndian(temp); temp = AuFlipEndian(temp);
#endif #endif
return temp; return temp;
#endif
} }
template<typename T> template<typename T>
static auline T AuReadGenericBE(const void *ptr, int offset) static auline T AuReadGenericBE(const void *ptr, int offset)
{ {
#if defined(AURORA_PERMIT_ARBITRARY_REF) && defined(AU_CPU_ENDIAN_BIG) #if defined(AURORA_PERMIT_ARBITRARY_REF)
return *reinterpret_cast<const T *>(reinterpret_cast<const AuUInt8 *>(ptr) + offset); T temp = *reinterpret_cast<const T *>(reinterpret_cast<const AuUInt8 *>(ptr) + offset);
#else #else
T temp; T temp;
AuMemcpy(&temp, reinterpret_cast<const AuUInt8 *>(ptr) + offset, sizeof(temp)); AuMemcpy(&temp, reinterpret_cast<const AuUInt8 *>(ptr) + offset, sizeof(temp));
#endif
#if defined(AU_CPU_ENDIAN_LITTLE) #if defined(AU_CPU_ENDIAN_LITTLE)
temp = AuFlipEndian(temp); temp = AuFlipEndian(temp);
#endif #endif
return temp; return temp;
#endif
} }
static auline AuUInt64 AuReadU64LE(const void *ptr, int offset) static auline AuUInt64 AuReadU64LE(const void *ptr, int offset)
@ -196,28 +200,28 @@ static auline AuInt8 AuReadS8(const void *ptr, int offset)
template<typename T> template<typename T>
static auline void AuWriteGenericLE(void *ptr, int offset, T value) static auline void AuWriteGenericLE(void *ptr, int offset, T value)
{ {
#if defined(AURORA_PERMIT_ARBITRARY_REF) && defined(AU_CPU_ENDIAN_LITTLE) #if !defined(AU_CPU_ENDIAN_LITTLE)
value = AuFlipEndian(value);
#endif
#if defined(AURORA_PERMIT_ARBITRARY_REF)
*reinterpret_cast<T *>(reinterpret_cast<AuUInt8 *>(ptr) + offset) = value; *reinterpret_cast<T *>(reinterpret_cast<AuUInt8 *>(ptr) + offset) = value;
#else #else
T temp = value; AuMemcpy(reinterpret_cast<AuUInt8 *>(ptr) + offset, &value, sizeof(value));
#if !defined(AU_CPU_ENDIAN_LITTLE)
temp = AuFlipEndian(temp);
#endif
AuMemcpy(reinterpret_cast<AuUInt8 *>(ptr) + offset, &temp, sizeof(temp));
#endif #endif
} }
template<typename T> template<typename T>
static auline void AuWriteGenericBE(void *ptr, T value, int offset) static auline void AuWriteGenericBE(void *ptr, T value, int offset)
{ {
#if defined(AURORA_PERMIT_ARBITRARY_REF) && defined(AU_CPU_ENDIAN_BIG) #if defined(AU_CPU_ENDIAN_LITTLE)
value = AuFlipEndian(value);
#endif
#if defined(AURORA_PERMIT_ARBITRARY_REF)
*reinterpret_cast<T *>(reinterpret_cast<AuUInt8 *>(ptr) + offset) = value; *reinterpret_cast<T *>(reinterpret_cast<AuUInt8 *>(ptr) + offset) = value;
#else #else
T temp = value; AuMemcpy(reinterpret_cast<AuUInt8 *>(ptr) + offset, &value, sizeof(value));
#if defined(AU_CPU_ENDIAN_LITTLE)
temp = AuFlipEndian(temp);
#endif
AuMemcpy(reinterpret_cast<AuUInt8 *>(ptr) + offset, &temp, sizeof(temp));
#endif #endif
} }