Make SDL_ObjectValid() inline for performance (thanks @mechakotik!)

This commit is contained in:
Sam Lantinga
2025-09-17 07:43:35 -07:00
parent 25b2d2c821
commit c25a0b046a
2 changed files with 18 additions and 11 deletions

View File

@@ -137,7 +137,7 @@ Uint32 SDL_GetNextObjectID(void)
static SDL_InitState SDL_objects_init;
static SDL_HashTable *SDL_objects;
static bool SDL_object_validation;
bool SDL_object_validation = false;
static void SDLCALL SDL_InvalidParamChecksChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
{
@@ -195,16 +195,8 @@ void SDL_SetObjectValid(void *object, SDL_ObjectType type, bool valid)
}
}
bool SDL_ObjectValid(void *object, SDL_ObjectType type)
bool SDL_FindObject(void *object, SDL_ObjectType type)
{
if (!object) {
return false;
}
if (!SDL_object_validation) {
return true;
}
const void *object_type;
if (!SDL_FindInHashTable(SDL_objects, object, &object_type)) {
return false;

View File

@@ -67,10 +67,25 @@ typedef enum
extern Uint32 SDL_GetNextObjectID(void);
extern void SDL_SetObjectValid(void *object, SDL_ObjectType type, bool valid);
extern bool SDL_ObjectValid(void *object, SDL_ObjectType type);
extern bool SDL_FindObject(void *object, SDL_ObjectType type);
extern int SDL_GetObjects(SDL_ObjectType type, void **objects, int count);
extern void SDL_SetObjectsInvalid(void);
extern bool SDL_object_validation;
SDL_FORCE_INLINE bool SDL_ObjectValid(void *object, SDL_ObjectType type)
{
if (!object) {
return false;
}
if (!SDL_object_validation) {
return true;
}
return SDL_FindObject(object, type);
}
extern const char *SDL_GetPersistentString(const char *string);
extern char *SDL_CreateDeviceName(Uint16 vendor, Uint16 product, const char *vendor_name, const char *product_name, const char *default_name);