[*] 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>
static auline T AuReadGenericLE(const void *ptr, int offset)
{
#if defined(AURORA_PERMIT_ARBITRARY_REF) && defined(AU_CPU_ENDIAN_LITTLE)
return *reinterpret_cast<const T *>(reinterpret_cast<const AuUInt8 *>(ptr) + offset);
#if defined(AURORA_PERMIT_ARBITRARY_REF)
T temp = *reinterpret_cast<const T *>(reinterpret_cast<const AuUInt8 *>(ptr) + offset);
#else
T temp;
AuMemcpy(&temp, reinterpret_cast<const AuUInt8 *>(ptr) + offset, sizeof(temp));
#endif
#if !defined(AU_CPU_ENDIAN_LITTLE)
temp = AuFlipEndian(temp);
#endif
return temp;
#endif
}
template<typename T>
static auline T AuReadGenericBE(const void *ptr, int offset)
{
#if defined(AURORA_PERMIT_ARBITRARY_REF) && defined(AU_CPU_ENDIAN_BIG)
return *reinterpret_cast<const T *>(reinterpret_cast<const AuUInt8 *>(ptr) + offset);
#if defined(AURORA_PERMIT_ARBITRARY_REF)
T temp = *reinterpret_cast<const T *>(reinterpret_cast<const AuUInt8 *>(ptr) + offset);
#else
T temp;
AuMemcpy(&temp, reinterpret_cast<const AuUInt8 *>(ptr) + offset, sizeof(temp));
#endif
#if defined(AU_CPU_ENDIAN_LITTLE)
temp = AuFlipEndian(temp);
#endif
return temp;
#endif
}
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>
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;
#else
T temp = value;
#if !defined(AU_CPU_ENDIAN_LITTLE)
temp = AuFlipEndian(temp);
#endif
AuMemcpy(reinterpret_cast<AuUInt8 *>(ptr) + offset, &temp, sizeof(temp));
AuMemcpy(reinterpret_cast<AuUInt8 *>(ptr) + offset, &value, sizeof(value));
#endif
}
template<typename T>
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;
#else
T temp = value;
#if defined(AU_CPU_ENDIAN_LITTLE)
temp = AuFlipEndian(temp);
#endif
AuMemcpy(reinterpret_cast<AuUInt8 *>(ptr) + offset, &temp, sizeof(temp));
AuMemcpy(reinterpret_cast<AuUInt8 *>(ptr) + offset, &value, sizeof(value));
#endif
}