summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2017-10-13 09:21:28 +0100
committerRichard Hughes <richard@hughsie.com>2017-10-13 09:21:28 +0100
commit326ecb0984ee66da3491f5f83942b81740bf5c4e (patch)
tree8d7d42b2452c764730a099ea86defac492118f49
parent946d1d6ccfea5270c33f01404769a8b473fc9020 (diff)
downloadappstream-glib-326ecb0984ee66da3491f5f83942b81740bf5c4e.tar.gz
trivial: Use a helper macro to make the bit-shifting easier to read
-rw-r--r--libappstream-glib/as-utils.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/libappstream-glib/as-utils.c b/libappstream-glib/as-utils.c
index f46f1fd..5526a2d 100644
--- a/libappstream-glib/as-utils.c
+++ b/libappstream-glib/as-utils.c
@@ -1557,6 +1557,8 @@ as_utils_guid_from_string (const gchar *str)
(const guint8 *) str, strlen (str), NULL);
}
+#define AS_UTILS_DECODE_BCD(val) ((((val) >> 4) & 0x0f) * 10 + ((val) & 0x0f))
+
/**
* as_utils_version_from_uint32:
* @val: A uint32le version number
@@ -1599,9 +1601,9 @@ gchar *
as_utils_version_from_uint16 (guint16 val, AsVersionParseFlag flags)
{
if (flags & AS_VERSION_PARSE_FLAG_USE_BCD) {
- guint maj = ((val >> 12) & 0x0f) * 10 + ((val >> 8) & 0x0f);
- guint min = ((val >> 4) & 0x0f) * 10 + (val & 0x0f);
- return g_strdup_printf ("%u.%u", maj, min);
+ return g_strdup_printf ("%u.%u",
+ AS_UTILS_DECODE_BCD(val >> 8),
+ AS_UTILS_DECODE_BCD(val));
}
return g_strdup_printf ("%u.%u",
(guint) (val >> 8) & 0xff,