- LttvHookClosure *c1, *c2;
-
- guint i, j;
-
- if(unlikely(h1 != NULL)) {
- if(unlikely(h2 != NULL)) {
- for(i = 0, j = 0 ; i < h1->len && j < h2->len ;) {
- c1 = &g_array_index(h1, LttvHookClosure, i);
- c2 = &g_array_index(h2, LttvHookClosure, j);
- if(c1->prio <= c2->prio) {
- if(c1->hook(c1->hook_data,call_data1)) return TRUE;
- i++;
- }
- else {
- if(c2->hook(c2->hook_data,call_data2)) return TRUE;
- j++;
- }
- }
- /* Finish the last list with hooks left */
- for(;i < h1->len; i++) {
- c1 = &g_array_index(h1, LttvHookClosure, i);
- if(c1->hook(c1->hook_data,call_data1)) return TRUE;
- }
- for(;j < h2->len; j++) {
- c2 = &g_array_index(h2, LttvHookClosure, j);
- if(c2->hook(c2->hook_data,call_data2)) return TRUE;
- }
- } else { /* h2 == NULL && h1 != NULL */
- for(i = 0 ; i < h1->len ; i++) {
- c1 = &g_array_index(h1, LttvHookClosure, i);
- if(c1->hook(c1->hook_data,call_data1)) return TRUE;
- }
- }
- } else if(likely(h2 != NULL)) { /* h1 == NULL && h2 != NULL */
- for(j = 0 ; j < h2->len ; j++) {
- c2 = &g_array_index(h2, LttvHookClosure, j);
- if(c2->hook(c2->hook_data,call_data2)) return TRUE;
- }
- }
-
- 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;
+ LttvHookClosure *c1, *c2;
+
+ guint i, j;
+
+ if(unlikely(h1 != NULL)) {
+ if(unlikely(h2 != NULL)) {
+ for(i = 0, j = 0 ; i < h1->len && j < h2->len ;) {
+ c1 = &g_array_index(h1, LttvHookClosure, i);
+ c2 = &g_array_index(h2, LttvHookClosure, j);
+ if(c1->prio <= c2->prio) {
+ if(c1->hook(c1->hook_data,call_data1)) return TRUE;
+ i++;
+ } else {
+ if(c2->hook(c2->hook_data,call_data2)) return TRUE;
+ j++;
+ }
+ }
+ /* Finish the last list with hooks left */
+ for(;i < h1->len; i++) {
+ c1 = &g_array_index(h1, LttvHookClosure, i);
+ if(c1->hook(c1->hook_data,call_data1)) return TRUE;
+ }
+ for(;j < h2->len; j++) {
+ c2 = &g_array_index(h2, LttvHookClosure, j);
+ if(c2->hook(c2->hook_data,call_data2)) return TRUE;
+ }
+ } else { /* h2 == NULL && h1 != NULL */
+ for(i = 0 ; i < h1->len ; i++) {
+ c1 = &g_array_index(h1, LttvHookClosure, i);
+ if(c1->hook(c1->hook_data,call_data1)) return TRUE;
+ }
+ }
+ } else if(likely(h2 != NULL)) { /* h1 == NULL && h2 != NULL */
+ for(j = 0 ; j < h2->len ; j++) {
+ c2 = &g_array_index(h2, LttvHookClosure, j);
+ if(c2->hook(c2->hook_data,call_data2)) return TRUE;
+ }
+ }
+
+ return FALSE;