Branchless GetExtendedID

This commit is contained in:
Silent 2017-06-20 20:35:35 +02:00
parent 9eec64ab83
commit 07d994cc3e
2 changed files with 8 additions and 6 deletions

View File

@ -3,7 +3,7 @@
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
int32_t (*FLAUtils::GetExtendedIDFunc)(const void* ptr) = nullptr;
int32_t (*FLAUtils::GetExtendedIDFunc)(const void* ptr) = FLAUtils::GetExtendedID_Stock;
void FLAUtils::Init()
{

View File

@ -7,11 +7,7 @@ class FLAUtils
public:
static int32_t GetExtendedID(const void* ptr)
{
if ( GetExtendedIDFunc != nullptr )
return GetExtendedIDFunc(ptr);
uint16_t uID = *static_cast<const uint16_t*>(ptr);
return uID > MAX_UINT16_ID ? *static_cast<const int16_t*>(ptr) : uID;
return GetExtendedIDFunc(ptr);
}
static void Init();
@ -19,5 +15,11 @@ public:
private:
static const int32_t MAX_UINT16_ID = 0xFFFD;
static int32_t GetExtendedID_Stock(const void* ptr)
{
uint16_t uID = *static_cast<const uint16_t*>(ptr);
return uID > MAX_UINT16_ID ? *static_cast<const int16_t*>(ptr) : uID;
}
static int32_t (*GetExtendedIDFunc)(const void* ptr);
};