mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-06 13:29:56 -05:00
object: speed up type verification by not relying on strcmp()
Instead of using string contents for type identification use the address of a constant string array. This should speed up type verifications a little sind we only need to compare one machine word instead of a full string. Also, this saves a few strings. To make clear that types must be compared via address and not string contents 'type_name' is now called 'type_id'. This also simplifies the macros for declaring and defining public and private subclasses.
This commit is contained in:
parent
5317e35543
commit
9abc010c93
19 changed files with 73 additions and 65 deletions
|
|
@ -28,21 +28,23 @@
|
|||
|
||||
#include "object.h"
|
||||
|
||||
pa_object *pa_object_new_internal(size_t size, const char *type_name, int (*check_type)(const char *type_name)) {
|
||||
const char pa_object_type_id[] = "pa_object";
|
||||
|
||||
pa_object *pa_object_new_internal(size_t size, const char *type_id, pa_bool_t (*check_type)(const char *type_id)) {
|
||||
pa_object *o;
|
||||
|
||||
pa_assert(size > sizeof(pa_object));
|
||||
pa_assert(type_name);
|
||||
pa_assert(type_id);
|
||||
|
||||
if (!check_type)
|
||||
check_type = pa_object_check_type;
|
||||
|
||||
pa_assert(check_type(type_name));
|
||||
pa_assert(check_type("pa_object"));
|
||||
pa_assert(check_type(type_id));
|
||||
pa_assert(check_type(pa_object_type_id));
|
||||
|
||||
o = pa_xmalloc(size);
|
||||
PA_REFCNT_INIT(o);
|
||||
o->type_name = type_name;
|
||||
o->type_id = type_id;
|
||||
o->free = pa_object_free;
|
||||
o->check_type = check_type;
|
||||
|
||||
|
|
@ -65,8 +67,8 @@ void pa_object_unref(pa_object *o) {
|
|||
}
|
||||
}
|
||||
|
||||
int pa_object_check_type(const char *type_name) {
|
||||
pa_assert(type_name);
|
||||
pa_bool_t pa_object_check_type(const char *type_id) {
|
||||
pa_assert(type_id);
|
||||
|
||||
return pa_streq(type_name, "pa_object");
|
||||
return type_id == pa_object_type_id;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue