- for(i = 0 ; i < list->len; i++) {
- g_array_append_val(h,g_array_index(list, LttvHookClosure, i));
+ for(i = 0, j = 0 ; i < list->len; i++) {
+ new_c = &g_array_index(list, LttvHookClosure, i);
+ gboolean found=FALSE;
+
+ /* Preliminary check for duplication */
+ /* only hook and hook data is checked, not priority */
+ for(k = 0; k < h->len; k++) {
+ c = &g_array_index(h, LttvHookClosure, k);
+ if(new_c->hook == c->hook && new_c->hook_data == c->hook_data) {
+ /* Found another identical entry : increment its ref_count and
+ * jump over the source index */
+ g_assert(new_c->prio == c->prio);
+ found=TRUE;
+ c->ref_count++;
+ break;
+ }
+ }
+
+ if(!found) {
+ /* If not found, add it to the destination array */
+ while(j < h->len) {
+ c = &g_array_index(h, LttvHookClosure, j);
+ if(new_c->prio < c->prio) {
+ g_array_insert_val(h,j,*new_c);
+ j++;
+ break;
+ }
+ else j++;
+ }
+ if(j == h->len) {
+ g_array_append_val(h,*new_c);
+ j++;
+ }
+ }