summaryrefslogtreecommitdiff
path: root/dbus/dbus-marshal-header.c
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2011-06-10 10:10:54 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2011-07-11 17:54:36 +0100
commit47fb9da6ad7123c5095bd4623ac0d745abcca677 (patch)
treec5c54407a5c2f3976e8008feb764390b1b1db4f8 /dbus/dbus-marshal-header.c
parent56b9629d694e6baf92765eef0ea8a57b702c74ab (diff)
DBusMessage: don't redundantly store byte order, ask the DBusHeader
Reviewed-by: Thiago Macieira <thiago@kde.org> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=38287
Diffstat (limited to 'dbus/dbus-marshal-header.c')
-rw-r--r--dbus/dbus-marshal-header.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/dbus/dbus-marshal-header.c b/dbus/dbus-marshal-header.c
index a6c9b80d..2fdf5583 100644
--- a/dbus/dbus-marshal-header.c
+++ b/dbus/dbus-marshal-header.c
@@ -165,6 +165,20 @@ _dbus_header_cache_one (DBusHeader *header,
}
/**
+ * Returns the header's byte order.
+ *
+ * @param header the header
+ * @returns the byte order
+ */
+char
+_dbus_header_get_byte_order (const DBusHeader *header)
+{
+ _dbus_assert (_dbus_string_get_length (&header->data) > BYTE_ORDER_OFFSET);
+
+ return (char) _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET);
+}
+
+/**
* Revalidates the fields cache
*
* @param header the header
@@ -1468,21 +1482,19 @@ void
_dbus_header_byteswap (DBusHeader *header,
int new_order)
{
- unsigned char byte_order;
+ char byte_order;
- if (header->byte_order == new_order)
- return;
+ byte_order = _dbus_header_get_byte_order (header);
- byte_order = _dbus_string_get_byte (&header->data, BYTE_ORDER_OFFSET);
- _dbus_assert (header->byte_order == byte_order);
+ if (byte_order == new_order)
+ return;
_dbus_marshal_byteswap (&_dbus_header_signature_str,
- 0, header->byte_order,
+ 0, byte_order,
new_order,
&header->data, 0);
_dbus_string_set_byte (&header->data, BYTE_ORDER_OFFSET, new_order);
- header->byte_order = new_order;
}
/** @} */