]> granicus.if.org Git - handbrake/commitdiff
libhb: add hb_buffer_list_rem()
authorJohn Stebbins <jstebbins.hb@gmail.com>
Tue, 17 May 2016 15:24:55 +0000 (09:24 -0600)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Tue, 17 May 2016 15:24:55 +0000 (09:24 -0600)
libhb/common.c
libhb/common.h

index 45f46b13770f18ee6524fe6981d75d8184b56e5c..f282bbbcf6ce8a85ddf05553e29e41f074b6f6ea 100644 (file)
@@ -2797,6 +2797,40 @@ hb_buffer_t* hb_buffer_list_rem_tail(hb_buffer_list_t *list)
     return tail;
 }
 
+hb_buffer_t* hb_buffer_list_rem(hb_buffer_list_t *list, hb_buffer_t * b)
+{
+    hb_buffer_t * a;
+
+    if (list == NULL)
+    {
+        return NULL;
+    }
+    if (b == list->head)
+    {
+        return hb_buffer_list_rem_head(list);
+    }
+    a = list->head;
+    while (a != NULL && a->next != b)
+    {
+        a = a->next;
+    }
+    if (a == NULL)
+    {
+        // Buffer is not in the list
+        return NULL;
+    }
+    list->count--;
+    list->size -= b->size;
+    a->next = b->next;
+    if (list->tail == b)
+    {
+        list->tail = a;
+    }
+    b->next = NULL;
+
+    return b;
+}
+
 hb_buffer_t* hb_buffer_list_head(hb_buffer_list_t *list)
 {
     if (list == NULL)
index 040164ceb3fea6735127dd7e0c8ae2a2abc4e8ed..834b48518561d174c7003ae1b03040e393f06de1 100644 (file)
@@ -120,6 +120,7 @@ hb_buffer_t* hb_buffer_list_head(hb_buffer_list_t *list);
 hb_buffer_t* hb_buffer_list_rem_head(hb_buffer_list_t *list);
 hb_buffer_t* hb_buffer_list_tail(hb_buffer_list_t *list);
 hb_buffer_t* hb_buffer_list_rem_tail(hb_buffer_list_t *list);
+hb_buffer_t* hb_buffer_list_rem(hb_buffer_list_t *list, hb_buffer_t * b);
 hb_buffer_t* hb_buffer_list_clear(hb_buffer_list_t *list);
 hb_buffer_t* hb_buffer_list_set(hb_buffer_list_t *list, hb_buffer_t *buf);
 void hb_buffer_list_close(hb_buffer_list_t *list);