[gnome-settings-daemon/wip/xsettings-manager] xsettings: make the alignment padding clearer
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon/wip/xsettings-manager] xsettings: make the alignment padding clearer
- Date: Fri, 9 Mar 2012 17:42:05 +0000 (UTC)
commit 457d8b26c30c61be47632a3aef869c3b14f43d31
Author: Ryan Lortie <desrt desrt ca>
Date: Fri Mar 9 12:23:10 2012 -0500
xsettings: make the alignment padding clearer
Split the alignment padding into a separate function, document it and
modify the algorithm in a way that makes it slightly less efficient but
substantially more clear.
plugins/xsettings/xsettings-manager.c | 19 +++++++++++++------
1 files changed, 13 insertions(+), 6 deletions(-)
---
diff --git a/plugins/xsettings/xsettings-manager.c b/plugins/xsettings/xsettings-manager.c
index e71c3c0..947cc9e 100644
--- a/plugins/xsettings/xsettings-manager.c
+++ b/plugins/xsettings/xsettings-manager.c
@@ -273,6 +273,17 @@ xsettings_get_typecode (GVariant *value)
}
static void
+align_string (GString *string,
+ gint alignment)
+{
+ /* Adds nul-bytes to the string until its length is an even multiple
+ * of the specified alignment requirement.
+ */
+ while ((string->len % alignment) != 0)
+ g_string_append_c (string, '\0');
+}
+
+static void
setting_store (XSettingsSetting *setting,
GString *buffer)
{
@@ -290,9 +301,7 @@ setting_store (XSettingsSetting *setting,
len16 = strlen (setting->name);
g_string_append_len (buffer, (gchar *) &len16, 2);
g_string_append (buffer, setting->name);
-
- while (buffer->len & 3)
- g_string_append_c (buffer, '\0');
+ align_string (buffer, 4);
g_string_append_len (buffer, (gchar *) &setting->last_change_serial, 4);
@@ -306,9 +315,7 @@ setting_store (XSettingsSetting *setting,
len32 = stringlen;
g_string_append_len (buffer, (gchar *) &len32, 4);
g_string_append (buffer, string);
-
- while (buffer->len & 3)
- g_string_append_c (buffer, '\0');
+ align_string (buffer, 4);
}
else
/* GVariant format is the same as XSETTINGS format for the non-string types */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]