gconf r2763 - in trunk: . backends
- From: michael svn gnome org
- To: svn-commits-list gnome org
- Subject: gconf r2763 - in trunk: . backends
- Date: Tue, 10 Feb 2009 17:04:12 +0000 (UTC)
Author: michael
Date: Tue Feb 10 17:04:12 2009
New Revision: 2763
URL: http://svn.gnome.org/viewvc/gconf?rev=2763&view=rev
Log:
2009-02-10 Michael Meeks <michael meeks novell com>
* backends/markup-tree.c: instead of indenting with spaces, use
tabs for a 50% size saving in the generated XML, and a nice
parsing speedup. Also accelerate writing by avoiding lots of
un-necessary memory allocation.
Modified:
trunk/ChangeLog
trunk/backends/markup-tree.c
Modified: trunk/backends/markup-tree.c
==============================================================================
--- trunk/backends/markup-tree.c (original)
+++ trunk/backends/markup-tree.c Tue Feb 10 17:04:12 2009
@@ -3660,7 +3660,7 @@
* Save
*/
-#define INDENT_SPACES 8
+#define INDENT_SPACES 1
static gboolean write_list_children (GConfValue *value,
FILE *f,
@@ -3674,6 +3674,17 @@
GSList *local_schemas,
gboolean save_as_subtree);
+/* the common case - before we start interning */
+static const char write_indents_static[] =
+ "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" /* 16 */
+ "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; /* 32 */
+
+static const char *make_whitespace (int indent)
+{
+ int idx = MAX (sizeof (write_indents_static) - 1 - indent, 0);
+ return &write_indents_static[idx];
+}
+
static gboolean
write_value_element (GConfValue *value,
const char *closing_element,
@@ -3682,8 +3693,7 @@
GSList *local_schemas,
gboolean save_as_subtree)
{
- char *whitespace;
-
+ gboolean single_element = FALSE;
/* We are at the "<foo bar="whatever"" stage here,
* <foo> still missing the closing >
*/
@@ -3811,17 +3821,13 @@
s = g_markup_escape_text (gconf_value_get_string (value),
-1);
- whitespace = g_strnfill (indent + INDENT_SPACES, ' ');
-
if (fprintf (f, "%s<stringvalue>%s</stringvalue>\n",
- whitespace, s) < 0)
+ make_whitespace (indent + INDENT_SPACES), s) < 0)
{
- g_free (whitespace);
g_free (s);
return FALSE;
}
- g_free (whitespace);
g_free (s);
}
break;
@@ -3852,13 +3858,8 @@
break;
}
- whitespace = g_strnfill (indent, ' ');
- if (fprintf (f, "%s</%s>\n", whitespace, closing_element) < 0)
- {
- g_free (whitespace);
+ if (fprintf (f, "%s</%s>\n", make_whitespace (indent), closing_element) < 0)
return FALSE;
- }
- g_free (whitespace);
return TRUE;
}
@@ -3870,16 +3871,13 @@
{
GSList *tmp;
gboolean retval = FALSE;
- char *whitespace;
-
- whitespace = g_strnfill (indent, ' ');
tmp = gconf_value_get_list (value);
while (tmp != NULL)
{
GConfValue *li = tmp->data;
- if (fputs (whitespace, f) < 0)
+ if (fputs (make_whitespace (indent), f) < 0)
goto out;
if (fputs ("<li", f) < 0)
@@ -3895,8 +3893,6 @@
out:
- g_free (whitespace);
-
return retval;
}
@@ -3907,15 +3903,12 @@
{
GConfValue *child;
gboolean retval = FALSE;
- char *whitespace;
- whitespace = g_strnfill (indent, ' ');
-
child = gconf_value_get_car (value);
if (child != NULL)
{
- if (fputs (whitespace, f) < 0)
+ if (fputs (make_whitespace (indent), f) < 0)
goto out;
if (fputs ("<car", f) < 0)
@@ -3929,7 +3922,7 @@
if (child != NULL)
{
- if (fputs (whitespace, f) < 0)
+ if (fputs (make_whitespace (indent), f) < 0)
goto out;
if (fputs ("<cdr", f) < 0)
@@ -3943,8 +3936,6 @@
out:
- g_free (whitespace);
-
return retval;
}
@@ -3956,7 +3947,7 @@
gboolean write_descs)
{
gboolean retval;
- char *whitespace1, *whitespace2;
+ const char *whitespace1, *whitespace2;
char *s;
if (!write_descs && local_schema->default_value == NULL)
@@ -3964,8 +3955,8 @@
retval = FALSE;
- whitespace1 = g_strnfill (indent, ' ');
- whitespace2 = g_strnfill (indent + INDENT_SPACES, ' ');
+ whitespace1 = make_whitespace (indent);
+ whitespace2 = make_whitespace (indent + INDENT_SPACES);
if (fputs (whitespace1, f) < 0)
goto out;
@@ -4050,9 +4041,6 @@
out:
- g_free (whitespace1);
- g_free (whitespace2);
-
return retval;
}
@@ -4150,7 +4138,6 @@
{
LocalSchemaInfo *local_schema_info;
gboolean retval;
- char *whitespace;
retval = FALSE;
local_schema_info = NULL;
@@ -4169,11 +4156,9 @@
}
}
- whitespace = g_strnfill (indent, ' ');
-
g_assert (entry->name != NULL);
- if (fprintf (f, "%s<entry name=\"%s\"", whitespace, entry->name) < 0)
+ if (fprintf (f, "%s<entry name=\"%s\"", make_whitespace (indent), entry->name) < 0)
goto out;
if (local_schema_info == NULL)
@@ -4221,7 +4206,7 @@
TRUE))
goto out;
- if (fprintf (f, "%s</entry>\n", whitespace) < 0)
+ if (fprintf (f, "%s</entry>\n", make_whitespace (indent)) < 0)
goto out;
}
@@ -4229,8 +4214,6 @@
out:
- g_free (whitespace);
-
return retval;
}
@@ -4244,18 +4227,16 @@
{
GSList *tmp;
gboolean retval = FALSE;
- char *whitespace;
dir->not_in_filesystem = TRUE;
if (save_as_subtree && locale != NULL && dir->is_dir_empty)
return TRUE;
- whitespace = g_strnfill (indent, ' ');
-
g_assert (dir->name != NULL);
- if (fprintf (f, "%s<dir name=\"%s\">\n", whitespace, dir->name) < 0)
+ if (fprintf (f, "%s<dir name=\"%s\">\n",
+ make_whitespace (indent), dir->name) < 0)
goto out;
tmp = dir->entries;
@@ -4290,15 +4271,13 @@
tmp = tmp->next;
}
- if (fprintf (f, "%s</dir>\n", whitespace) < 0)
+ if (fprintf (f, "%s</dir>\n", make_whitespace (indent)) < 0)
return FALSE;
retval = TRUE;
out:
- g_free (whitespace);
-
return retval;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]