diff options
author | Tim-Philipp Müller <tim@centricular.com> | 2016-11-16 10:51:48 +0000 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.com> | 2016-11-16 10:57:33 +0000 |
commit | 06b015b62ac8559958af566166c5b17f6c1ac17e (patch) | |
tree | cba9e6facfaefd4b882e13359b8f5f83d2a588d5 | |
parent | 2e579a7c1bfd555fbbf5b27142bf16bc93429670 (diff) |
utils: use temp var in fallback GST_WRITE_*() macros
To make sure the value is only expanded/used once, in case
there are side effects to it, and to avoid calculating it
or looking it up multiple times if there is a calculation
or lookup involved.
-rw-r--r-- | gst/gstutils.h | 88 |
1 files changed, 48 insertions, 40 deletions
diff --git a/gst/gstutils.h b/gst/gstutils.h index 3004ee485..dd5e9b216 100644 --- a/gst/gstutils.h +++ b/gst/gstutils.h @@ -350,28 +350,30 @@ static inline guint16 __gst_slow_read16_le (const guint8 * data) { # define GST_WRITE_UINT64_LE(data,val) _GST_FAST_WRITE(64,data,val) # endif #else -#define GST_WRITE_UINT64_BE(data, num) do { \ +#define GST_WRITE_UINT64_BE(data,val) do { \ gpointer __put_data = data; \ - _GST_PUT (__put_data, 0, 64, 56, num); \ - _GST_PUT (__put_data, 1, 64, 48, num); \ - _GST_PUT (__put_data, 2, 64, 40, num); \ - _GST_PUT (__put_data, 3, 64, 32, num); \ - _GST_PUT (__put_data, 4, 64, 24, num); \ - _GST_PUT (__put_data, 5, 64, 16, num); \ - _GST_PUT (__put_data, 6, 64, 8, num); \ - _GST_PUT (__put_data, 7, 64, 0, num); \ + guint64 __put_val = val; \ + _GST_PUT (__put_data, 0, 64, 56, __put_val); \ + _GST_PUT (__put_data, 1, 64, 48, __put_val); \ + _GST_PUT (__put_data, 2, 64, 40, __put_val); \ + _GST_PUT (__put_data, 3, 64, 32, __put_val); \ + _GST_PUT (__put_data, 4, 64, 24, __put_val); \ + _GST_PUT (__put_data, 5, 64, 16, __put_val); \ + _GST_PUT (__put_data, 6, 64, 8, __put_val); \ + _GST_PUT (__put_data, 7, 64, 0, __put_val); \ } while (0) -#define GST_WRITE_UINT64_LE(data, num) do { \ +#define GST_WRITE_UINT64_LE(data,val) do { \ gpointer __put_data = data; \ - _GST_PUT (__put_data, 0, 64, 0, num); \ - _GST_PUT (__put_data, 1, 64, 8, num); \ - _GST_PUT (__put_data, 2, 64, 16, num); \ - _GST_PUT (__put_data, 3, 64, 24, num); \ - _GST_PUT (__put_data, 4, 64, 32, num); \ - _GST_PUT (__put_data, 5, 64, 40, num); \ - _GST_PUT (__put_data, 6, 64, 48, num); \ - _GST_PUT (__put_data, 7, 64, 56, num); \ + guint64 __put_val = val; \ + _GST_PUT (__put_data, 0, 64, 0, __put_val); \ + _GST_PUT (__put_data, 1, 64, 8, __put_val); \ + _GST_PUT (__put_data, 2, 64, 16, __put_val); \ + _GST_PUT (__put_data, 3, 64, 24, __put_val); \ + _GST_PUT (__put_data, 4, 64, 32, __put_val); \ + _GST_PUT (__put_data, 5, 64, 40, __put_val); \ + _GST_PUT (__put_data, 6, 64, 48, __put_val); \ + _GST_PUT (__put_data, 7, 64, 56, __put_val); \ } while (0) #endif /* !GST_HAVE_UNALIGNED_ACCESS */ @@ -398,20 +400,22 @@ static inline guint16 __gst_slow_read16_le (const guint8 * data) { # define GST_WRITE_UINT32_LE(data,val) _GST_FAST_WRITE(32,data,val) # endif #else -#define GST_WRITE_UINT32_BE(data, num) do { \ +#define GST_WRITE_UINT32_BE(data,val) do { \ gpointer __put_data = data; \ - _GST_PUT (__put_data, 0, 32, 24, num); \ - _GST_PUT (__put_data, 1, 32, 16, num); \ - _GST_PUT (__put_data, 2, 32, 8, num); \ - _GST_PUT (__put_data, 3, 32, 0, num); \ + guint32 __put_val = val; \ + _GST_PUT (__put_data, 0, 32, 24, __put_val); \ + _GST_PUT (__put_data, 1, 32, 16, __put_val); \ + _GST_PUT (__put_data, 2, 32, 8, __put_val); \ + _GST_PUT (__put_data, 3, 32, 0, __put_val); \ } while (0) -#define GST_WRITE_UINT32_LE(data, num) do { \ +#define GST_WRITE_UINT32_LE(data,val) do { \ gpointer __put_data = data; \ - _GST_PUT (__put_data, 0, 32, 0, num); \ - _GST_PUT (__put_data, 1, 32, 8, num); \ - _GST_PUT (__put_data, 2, 32, 16, num); \ - _GST_PUT (__put_data, 3, 32, 24, num); \ + guint32 __put_val = val; \ + _GST_PUT (__put_data, 0, 32, 0, __put_val); \ + _GST_PUT (__put_data, 1, 32, 8, __put_val); \ + _GST_PUT (__put_data, 2, 32, 16, __put_val); \ + _GST_PUT (__put_data, 3, 32, 24, __put_val); \ } while (0) #endif /* !GST_HAVE_UNALIGNED_ACCESS */ @@ -424,9 +428,10 @@ static inline guint16 __gst_slow_read16_le (const guint8 * data) { */ #define GST_WRITE_UINT24_BE(data, num) do { \ gpointer __put_data = data; \ - _GST_PUT (__put_data, 0, 32, 16, num); \ - _GST_PUT (__put_data, 1, 32, 8, num); \ - _GST_PUT (__put_data, 2, 32, 0, num); \ + guint32 __put_val = num; \ + _GST_PUT (__put_data, 0, 32, 16, __put_val); \ + _GST_PUT (__put_data, 1, 32, 8, __put_val); \ + _GST_PUT (__put_data, 2, 32, 0, __put_val); \ } while (0) /** @@ -438,9 +443,10 @@ static inline guint16 __gst_slow_read16_le (const guint8 * data) { */ #define GST_WRITE_UINT24_LE(data, num) do { \ gpointer __put_data = data; \ - _GST_PUT (__put_data, 0, 32, 0, num); \ - _GST_PUT (__put_data, 1, 32, 8, num); \ - _GST_PUT (__put_data, 2, 32, 16, num); \ + guint32 __put_val = num; \ + _GST_PUT (__put_data, 0, 32, 0, __put_val); \ + _GST_PUT (__put_data, 1, 32, 8, __put_val); \ + _GST_PUT (__put_data, 2, 32, 16, __put_val); \ } while (0) /** @@ -466,16 +472,18 @@ static inline guint16 __gst_slow_read16_le (const guint8 * data) { # define GST_WRITE_UINT16_LE(data,val) _GST_FAST_WRITE(16,data,val) # endif #else -#define GST_WRITE_UINT16_BE(data, num) do { \ +#define GST_WRITE_UINT16_BE(data,val) do { \ gpointer __put_data = data; \ - _GST_PUT (__put_data, 0, 16, 8, num); \ - _GST_PUT (__put_data, 1, 16, 0, num); \ + guint16 __put_val = val; \ + _GST_PUT (__put_data, 0, 16, 8, __put_val); \ + _GST_PUT (__put_data, 1, 16, 0, __put_val); \ } while (0) -#define GST_WRITE_UINT16_LE(data, num) do { \ +#define GST_WRITE_UINT16_LE(data,val) do { \ gpointer __put_data = data; \ - _GST_PUT (__put_data, 0, 16, 0, num); \ - _GST_PUT (__put_data, 1, 16, 8, num); \ + guint16 __put_val = val; \ + _GST_PUT (__put_data, 0, 16, 0, __put_val); \ + _GST_PUT (__put_data, 1, 16, 8, __put_val); \ } while (0) #endif /* !GST_HAVE_UNALIGNED_ACCESS */ |