diff options
author | Rob Staudinger <robsta@linux.intel.com> | 2011-09-14 16:02:44 +0200 |
---|---|---|
committer | Rob Staudinger <robsta@linux.intel.com> | 2011-09-14 16:02:44 +0200 |
commit | 5d48498ac946e83226dcdf5460f780f963a33c6b (patch) | |
tree | 94a98e1f9aecf58a4fbc494f8afba15620be5b1a | |
parent | 543c67940db0c20707532f61bcb5aa44105116ef (diff) |
factory: Use GArray for holding the lookup table, evading qsort.
-rw-r--r-- | ytstenut/yts-factory.c | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/ytstenut/yts-factory.c b/ytstenut/yts-factory.c index a3e194f..7b8d131 100644 --- a/ytstenut/yts-factory.c +++ b/ytstenut/yts-factory.c @@ -37,14 +37,14 @@ typedef struct { GType proxy_gtype; } FactoryEntry; -static FactoryEntry *_table = NULL; -static unsigned _table_size = 0; +static GArray *_table = NULL; static int -_factory_entry_compare (FactoryEntry const *fe1, - FactoryEntry const *fe2) +_factory_entry_compare (const void *fe1, + const void *fe2) { - return strcmp (fe1->fqc_id, fe2->fqc_id); + return strcmp (((FactoryEntry *) fe1)->fqc_id, + ((FactoryEntry *) fe2)->fqc_id); } static void @@ -58,11 +58,7 @@ yts_factory_class_init (YtsFactoryClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - struct { - char const *fqc_id; /* Needs to be first so we can use strcmp. */ - GType adapter_type; - GType proxy_type; - } table[] = { + FactoryEntry table[] = { { "org.freedesktop.ytstenut.VideoProfile.Player", yts_vp_player_adapter_get_type (), yts_vp_player_proxy_get_type () }, @@ -73,13 +69,16 @@ yts_factory_class_init (YtsFactoryClass *klass) object_class->dispose = _dispose; + g_debug ("%s : %i table size", G_STRLOC, sizeof (table)); + if (NULL == _table) { - _table = g_memdup (table, sizeof (table)); - _table_size = G_N_ELEMENTS (table); - qsort (_table, - _table_size, - sizeof (FactoryEntry), - (__compar_fn_t) _factory_entry_compare); + _table = g_array_sized_new (false, + false, + sizeof (FactoryEntry), + G_N_ELEMENTS (table)); + memcpy (_table->data, table, sizeof (table)); + _table->len = G_N_ELEMENTS (table); + g_array_sort (_table, _factory_entry_compare); } } @@ -97,10 +96,10 @@ yts_factory_has_fqc_id (YtsFactory const *self, needle.fqc_id = fqc_id; entry = bsearch (&needle, - _table, - _table_size, + _table->data, + _table->len, sizeof (FactoryEntry), - (__compar_fn_t) strcmp); + _factory_entry_compare); return (bool) entry; } @@ -114,10 +113,10 @@ yts_factory_get_proxy_gtype_for_fqc_id (YtsFactory const *self, needle.fqc_id = fqc_id; entry = bsearch (&needle, - _table, - _table_size, + _table->data, + _table->len, sizeof (FactoryEntry), - (__compar_fn_t) _factory_entry_compare); + _factory_entry_compare); g_return_val_if_fail (entry, G_TYPE_INVALID); @@ -133,10 +132,10 @@ yts_factory_get_adapter_gtype_for_fqc_id (YtsFactory const *self, needle.fqc_id = fqc_id; entry = bsearch (&needle, - _table, - _table_size, + _table->data, + _table->len, sizeof (FactoryEntry), - (__compar_fn_t) _factory_entry_compare); + _factory_entry_compare); g_return_val_if_fail (entry, G_TYPE_INVALID); |