Factor duplicated loop
authorVitor Sessak <vitor1001@gmail.com>
Sun, 10 Feb 2008 18:04:52 +0000 (18:04 +0000)
committerVitor Sessak <vitor1001@gmail.com>
Sun, 10 Feb 2008 18:04:52 +0000 (18:04 +0000)
Originally committed as revision 11899 to svn://svn.ffmpeg.org/ffmpeg/trunk

libavfilter/formats.c

index 4ce1ff7..d7d0322 100644 (file)
 
 #include "avfilter.h"
 
 
 #include "avfilter.h"
 
+/** merge and update all the references */
+static void merge_ref(AVFilterFormats *ret, AVFilterFormats *a)
+{
+    int i;
+    for(i = 0; i < a->refcount; i ++) {
+        ret->refs[ret->refcount] = a->refs[i];
+        *ret->refs[ret->refcount++] = ret;
+    }
+}
+
 AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
 {
     AVFilterFormats *ret;
 AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
 {
     AVFilterFormats *ret;
@@ -43,16 +53,10 @@ AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
         return NULL;
     }
 
         return NULL;
     }
 
-    /* merge and update all the references */
     ret->refs = av_malloc(sizeof(AVFilterFormats**)*(a->refcount+b->refcount));
     ret->refs = av_malloc(sizeof(AVFilterFormats**)*(a->refcount+b->refcount));
-    for(i = 0; i < a->refcount; i ++) {
-        ret->refs[ret->refcount] = a->refs[i];
-        *ret->refs[ret->refcount++] = ret;
-    }
-    for(i = 0; i < b->refcount; i ++) {
-        ret->refs[ret->refcount] = b->refs[i];
-        *ret->refs[ret->refcount++] = ret;
-    }
+
+    merge_ref(ret, a);
+    merge_ref(ret, b);
 
     av_free(a->refs);
     av_free(a->formats);
 
     av_free(a->refs);
     av_free(a->formats);