}
-LttvHooks *lttv_hooks_new()
+LttvHooks *lttv_hooks_new(void)
{
return g_array_new(FALSE, FALSE, sizeof(LttvHookClosure));
}
}
return FALSE;
-
-}
-
-/* Two pointer arrays :
- * * one indexed by id for quick search :
- * size : max id
- * typically 4 bytes * 256 facilities * 10 events = 10kbytes
- * * another array that keeps a list of used numbers (for later deletion)
- * size : number of ids used.
- */
-
-LttvHooksById *lttv_hooks_by_id_new()
-{
- LttvHooksById *h = g_new(LttvHooksById, 1);
- h->index = g_ptr_array_sized_new(PREALLOC_EVENTS);
- h->array = g_array_sized_new(FALSE, FALSE, sizeof(guint), PREALLOC_EVENTS);
- return h;
-}
-
-
-void lttv_hooks_by_id_destroy(LttvHooksById *h)
-{
- guint i;
-
- for(i = 0 ; i < h->array->len ; i++) {
- guint index = g_array_index(h->array, guint, i);
- if(h->index->pdata[index] != NULL) { /* hook may have been removed */
- lttv_hooks_destroy(h->index->pdata[index]);
- h->index->pdata[index] = NULL; /* Must be there in case of
- multiple addition of the same index */
- }
- }
- g_ptr_array_free(h->index, TRUE);
- g_array_free(h->array, TRUE);
-}
-
-/* Optimised for searching an existing hook */
-LttvHooks *lttv_hooks_by_id_find(LttvHooksById *h, unsigned id)
-{
- if(unlikely(h->index->len <= id)) g_ptr_array_set_size(h->index, id + 1);
- if(unlikely(h->index->pdata[id] == NULL)) {
- h->index->pdata[id] = lttv_hooks_new();
- g_array_append_val(h->array, id);
- }
- return h->index->pdata[id];
-}
-
-
-unsigned lttv_hooks_by_id_max_id(LttvHooksById *h)
-{
- return h->index->len;
-}
-
-/* We don't bother removing the used slot array id : lttv_hooks_by_id_destroy is
- * almost never called and is able to deal with used slot repetition. */
-void lttv_hooks_by_id_remove(LttvHooksById *h, unsigned id)
-{
- if(likely(id < h->index->len && h->index->pdata[id] != NULL)) {
- lttv_hooks_destroy((LttvHooks *)h->index->pdata[id]);
- h->index->pdata[id] = NULL;
- }
-}
-
-void lttv_hooks_by_id_copy(LttvHooksById *dest, LttvHooksById *src)
-{
- guint i;
-
- for(i = 0 ; i < src->array->len ; i++) {
- guint index = g_array_index(src->array, guint, i);
- LttvHooks *srch = lttv_hooks_by_id_find(src, index);
- LttvHooks *desth = lttv_hooks_by_id_find(dest, index);
- lttv_hooks_add_list(desth, srch);
- }
-}
-
-LttvHooksByIdChannelArray *lttv_hooks_by_id_channel_new(void)
-{
- LttvHooksByIdChannelArray *h = g_new(LttvHooksByIdChannelArray, 1);
-
- h->array = g_array_new(FALSE, FALSE, sizeof(LttvHooksByIdChannel));
- return h;
-}
-
-void lttv_hooks_by_id_channel_destroy(LttvHooksByIdChannelArray *h)
-{
- LttvHooksByIdChannel *hid;
- int i;
-
- for (i = 0; i < h->array->len; i++) {
- hid = &g_array_index(h->array, LttvHooksByIdChannel, i);
- lttv_hooks_by_id_destroy(hid->hooks_by_id);
- }
- g_array_free(h->array, TRUE);
- g_free(h);
-}
-
-static LttvHooksByIdChannel *
-lttv_hooks_by_id_channel_find_channel(LttvHooksByIdChannelArray *h,
- GQuark channel)
-{
- LttvHooksByIdChannel *hid;
- int i, found = 0;
-
- for (i = 0; i < h->array->len; i++) {
- hid = &g_array_index(h->array, LttvHooksByIdChannel, i);
- if (hid->channel == channel) {
- found = 1;
- break;
- }
- }
- if (!found) {
- g_array_set_size(h->array, h->array->len + 1);
- hid = &g_array_index(h->array, LttvHooksByIdChannel, h->array->len - 1);
- hid->channel = channel;
- hid->hooks_by_id = lttv_hooks_by_id_new();
- }
- return hid;
-}
-
-/* get, or create if not found */
-LttvHooks *lttv_hooks_by_id_channel_find(LttvHooksByIdChannelArray *h,
- GQuark channel, guint16 id)
-{
- LttvHooksByIdChannel *hid;
- hid = lttv_hooks_by_id_channel_find_channel(h, channel);
- return lttv_hooks_by_id_find(hid->hooks_by_id, id);
}