Skip to content

Commit bbb841b

Browse files
committed
Make SDL_ObjectValid() inline for performance (thanks @mechakotik!)
1 parent 4a59dc1 commit bbb841b

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/SDL_utils.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Uint32 SDL_GetNextObjectID(void)
137137

138138
static SDL_InitState SDL_objects_init;
139139
static SDL_HashTable *SDL_objects;
140-
static bool SDL_object_validation;
140+
bool SDL_object_validation = false;
141141

142142
static void SDLCALL SDL_InvalidParamChecksChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
143143
{
@@ -195,16 +195,8 @@ void SDL_SetObjectValid(void *object, SDL_ObjectType type, bool valid)
195195
}
196196
}
197197

198-
bool SDL_ObjectValid(void *object, SDL_ObjectType type)
198+
bool SDL_FindObject(void *object, SDL_ObjectType type)
199199
{
200-
if (!object) {
201-
return false;
202-
}
203-
204-
if (!SDL_object_validation) {
205-
return true;
206-
}
207-
208200
const void *object_type;
209201
if (!SDL_FindInHashTable(SDL_objects, object, &object_type)) {
210202
return false;

src/SDL_utils_c.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,25 @@ typedef enum
6767

6868
extern Uint32 SDL_GetNextObjectID(void);
6969
extern void SDL_SetObjectValid(void *object, SDL_ObjectType type, bool valid);
70-
extern bool SDL_ObjectValid(void *object, SDL_ObjectType type);
70+
extern bool SDL_FindObject(void *object, SDL_ObjectType type);
7171
extern int SDL_GetObjects(SDL_ObjectType type, void **objects, int count);
7272
extern void SDL_SetObjectsInvalid(void);
7373

74+
extern bool SDL_object_validation;
75+
76+
SDL_FORCE_INLINE bool SDL_ObjectValid(void *object, SDL_ObjectType type)
77+
{
78+
if (!object) {
79+
return false;
80+
}
81+
82+
if (!SDL_object_validation) {
83+
return true;
84+
}
85+
86+
return SDL_FindObject(object, type);
87+
}
88+
7489
extern const char *SDL_GetPersistentString(const char *string);
7590

7691
extern char *SDL_CreateDeviceName(Uint16 vendor, Uint16 product, const char *vendor_name, const char *product_name, const char *default_name);

0 commit comments

Comments
 (0)