[libbluray-devel] bd_uo_mask_combine(): use union (simpler and safer)

hpi1 git at videolan.org
Wed Jul 2 14:38:29 CEST 2014


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Wed Jul  2 14:20:46 2014 +0300| [7bae4ff21bdc4ec0a9c5c997ad63ff490293e297] | committer: hpi1

bd_uo_mask_combine(): use union (simpler and safer)

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=7bae4ff21bdc4ec0a9c5c997ad63ff490293e297
---

 src/libbluray/bdnav/uo_mask_table.h |   17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/libbluray/bdnav/uo_mask_table.h b/src/libbluray/bdnav/uo_mask_table.h
index bfd210e..71792d9 100644
--- a/src/libbluray/bdnav/uo_mask_table.h
+++ b/src/libbluray/bdnav/uo_mask_table.h
@@ -62,17 +62,16 @@ typedef struct bd_uo_mask_table_s
 
 static inline BD_UO_MASK bd_uo_mask_combine(BD_UO_MASK a, BD_UO_MASK b)
 {
-    BD_UO_MASK o;
-    unsigned int   *pa = (unsigned int*)&a;
-    unsigned int   *pb = (unsigned int*)&b;
-    unsigned int   *po = (unsigned int*)&o;
-    unsigned   i;
+    union {
+        BD_UO_MASK mask;
+        uint64_t   u64;
+    } mask_a, mask_b, result;
 
-    for (i = 0; i < sizeof(BD_UO_MASK) / sizeof(unsigned int); i++) {
-        po[i] = pa[i] | pb[i];
-    }
+    mask_a.mask = a;
+    mask_b.mask = b;
+    result.u64 = mask_a.u64 | mask_b.u64;
 
-    return o;
+    return result.mask;
 }
 
 #endif // _BD_UO_MASK_TABLE_H_



More information about the libbluray-devel mailing list