summaryrefslogtreecommitdiff
path: root/libavfilter/formats.c
diff options
context:
space:
mode:
authorVitor Sessak <vitor1001@gmail.com>2008-02-10 18:04:52 +0000
committerVitor Sessak <vitor1001@gmail.com>2008-02-10 18:04:52 +0000
commit37e0b997a8d6695abb0dd4bac886a86104d68a3c (patch)
tree3935d670fda66efbbf70cd5df8b87a609b288844 /libavfilter/formats.c
parentd3a4e41c8a15fe1471951ed1a334d24072b9e0c2 (diff)
Factor duplicated loop
Originally committed as revision 11899 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavfilter/formats.c')
-rw-r--r--libavfilter/formats.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index 4ce1ff70db..d7d0322963 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -21,6 +21,16 @@
#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;
@@ -43,16 +53,10 @@ AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b)
return NULL;
}
- /* merge and update all the references */
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);