[FFmpeg-devel] [PATCH] ffprobe: Eliminate pointless union in unit_value struct

Derek Buitenhuis derek.buitenhuis at gmail.com
Wed Sep 12 17:18:46 CEST 2012


There is no point to this union, as even if it is passed an integer,
it is immediately put into a double anyway, inside the only function
that uses it.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis at gmail.com>
---
 ffprobe.c |   14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/ffprobe.c b/ffprobe.c
index 06af4c3..8a1e055 100644
--- a/ffprobe.c
+++ b/ffprobe.c
@@ -89,7 +89,7 @@ void av_noreturn exit_program(int ret)
 }
 
 struct unit_value {
-    union { double d; long long int i; } val;
+    double val;
     const char *unit;
 };
 
@@ -98,12 +98,10 @@ static char *value_string(char *buf, int buf_size, struct unit_value uv)
     double vald;
     int show_float = 0;
 
-    if (uv.unit == unit_second_str) {
-        vald = uv.val.d;
+    if (uv.unit == unit_second_str)
         show_float = 1;
-    } else {
-        vald = uv.val.i;
-    }
+
+    vald = uv.val;
 
     if (uv.unit == unit_second_str && use_value_sexagesimal_format) {
         double secs;
@@ -355,7 +353,7 @@ static void writer_print_time(WriterContext *wctx, const char *key,
             writer_print_string(wctx, key, "N/A", 1);
         } else {
             double d = ts * av_q2d(*time_base);
-            value_string(buf, sizeof(buf), (struct unit_value){.val.d=d, .unit=unit_second_str});
+            value_string(buf, sizeof(buf), (struct unit_value){.val=d, .unit=unit_second_str});
             writer_print_string(wctx, key, buf, 0);
         }
     }
@@ -1442,7 +1440,7 @@ static void writer_register_all(void)
 #define print_duration_time(k, v, tb) writer_print_time(w, k, v, tb, 1)
 #define print_duration_ts(k, v)       writer_print_ts(w, k, v, 1)
 #define print_val(k, v, u)      writer_print_string(w, k, \
-    value_string(val_str, sizeof(val_str), (struct unit_value){.val.i = v, .unit=u}), 0)
+    value_string(val_str, sizeof(val_str), (struct unit_value){.val = (double)v, .unit=u}), 0)
 #define print_section_header(s) writer_print_section_header(w, s)
 #define print_section_footer(s) writer_print_section_footer(w, s)
 #define show_tags(metadata)     writer_show_tags(w, metadata)
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list