[libgdata] [core] Made the get_xml functions use a single GString throughout
- From: Philip Withnall <pwithnall src gnome org>
- To: svn-commits-list gnome org
- Subject: [libgdata] [core] Made the get_xml functions use a single GString throughout
- Date: Sat, 4 Jul 2009 13:55:15 +0000 (UTC)
commit 97355e5cfc3bb12afb30b690aa0e4b185457b931
Author: Philip Withnall <philip tecnocode co uk>
Date: Fri Jul 3 10:12:09 2009 +0100
[core] Made the get_xml functions use a single GString throughout
Previously, each call to _gdata_parsable_get_xml would create its own GString,
then destroy it at the end. Now, the same GString is reused throughout a tree
of calls to _gdata_parsable_get_xml, saving quite a few allocations/frees
(in exchange for more reallocations).
gdata/gd/gdata-gd-when.c | 7 ++-----
gdata/gdata-entry.c | 21 ++++++---------------
gdata/gdata-parsable.c | 12 +++++-------
gdata/gdata-private.h | 2 +-
gdata/media/gdata-media-group.c | 7 ++-----
gdata/services/calendar/gdata-calendar-event.c | 7 ++-----
gdata/services/contacts/gdata-contacts-contact.c | 7 ++-----
gdata/services/picasaweb/gdata-picasaweb-album.c | 5 +----
gdata/services/picasaweb/gdata-picasaweb-file.c | 5 +----
gdata/services/youtube/gdata-youtube-video.c | 9 ++-------
10 files changed, 24 insertions(+), 58 deletions(-)
---
diff --git a/gdata/gd/gdata-gd-when.c b/gdata/gd/gdata-gd-when.c
index 3f0468d..04066e5 100644
--- a/gdata/gd/gdata-gd-when.c
+++ b/gdata/gd/gdata-gd-when.c
@@ -357,11 +357,8 @@ get_xml (GDataParsable *parsable, GString *xml_string)
GList *reminders;
GDataGDWhenPrivate *priv = GDATA_GD_WHEN (parsable)->priv;
- for (reminders = priv->reminders; reminders != NULL; reminders = reminders->next) {
- gchar *xml = _gdata_parsable_get_xml (GDATA_PARSABLE (reminders->data), FALSE);
- g_string_append (xml_string, xml);
- g_free (xml);
- }
+ for (reminders = priv->reminders; reminders != NULL; reminders = reminders->next)
+ _gdata_parsable_get_xml (GDATA_PARSABLE (reminders->data), xml_string, FALSE);
}
static void
diff --git a/gdata/gdata-entry.c b/gdata/gdata-entry.c
index 72f1a73..4ce3abc 100644
--- a/gdata/gdata-entry.c
+++ b/gdata/gdata-entry.c
@@ -444,23 +444,14 @@ get_xml (GDataParsable *parsable, GString *xml_string)
g_free (content);
}
- for (categories = priv->categories; categories != NULL; categories = categories->next) {
- gchar *xml = _gdata_parsable_get_xml (GDATA_PARSABLE (categories->data), FALSE);
- g_string_append (xml_string, xml);
- g_free (xml);
- }
+ for (categories = priv->categories; categories != NULL; categories = categories->next)
+ _gdata_parsable_get_xml (GDATA_PARSABLE (categories->data), xml_string, FALSE);
- for (links = priv->links; links != NULL; links = links->next) {
- gchar *xml = _gdata_parsable_get_xml (GDATA_PARSABLE (links->data), FALSE);
- g_string_append (xml_string, xml);
- g_free (xml);
- }
+ for (links = priv->links; links != NULL; links = links->next)
+ _gdata_parsable_get_xml (GDATA_PARSABLE (links->data), xml_string, FALSE);
- for (authors = priv->authors; authors != NULL; authors = authors->next) {
- gchar *xml = _gdata_parsable_get_xml (GDATA_PARSABLE (authors->data), FALSE);
- g_string_append (xml_string, xml);
- g_free (xml);
- }
+ for (authors = priv->authors; authors != NULL; authors = authors->next)
+ _gdata_parsable_get_xml (GDATA_PARSABLE (authors->data), xml_string, FALSE);
}
static void
diff --git a/gdata/gdata-parsable.c b/gdata/gdata-parsable.c
index 7f6a7a6..dc5efc3 100644
--- a/gdata/gdata-parsable.c
+++ b/gdata/gdata-parsable.c
@@ -259,7 +259,9 @@ filter_namespaces_cb (gchar *prefix, gchar *href, GHashTable *canonical_namespac
gchar *
gdata_parsable_get_xml (GDataParsable *self)
{
- return _gdata_parsable_get_xml (self, TRUE);
+ GString *xml_string = g_string_sized_new (100);
+ _gdata_parsable_get_xml (self, xml_string, TRUE);
+ return g_string_free (xml_string, FALSE);
}
/*
@@ -273,11 +275,10 @@ gdata_parsable_get_xml (GDataParsable *self)
*
* Return value: the object's XML; free with g_free()
*/
-gchar *
-_gdata_parsable_get_xml (GDataParsable *self, gboolean declare_namespaces)
+void
+_gdata_parsable_get_xml (GDataParsable *self, GString *xml_string, gboolean declare_namespaces)
{
GDataParsableClass *klass;
- GString *xml_string;
guint length;
GHashTable *namespaces = NULL; /* shut up, gcc */
@@ -294,7 +295,6 @@ _gdata_parsable_get_xml (GDataParsable *self, gboolean declare_namespaces)
}
/* Build up the namespace list */
- xml_string = g_string_sized_new (100);
if (klass->element_namespace != NULL)
g_string_append_printf (xml_string, "<%s:%s", klass->element_namespace, klass->element_name);
else
@@ -334,6 +334,4 @@ _gdata_parsable_get_xml (GDataParsable *self, gboolean declare_namespaces)
g_string_append_printf (xml_string, "</%s:%s>", klass->element_namespace, klass->element_name);
else
g_string_append_printf (xml_string, "</%s>", klass->element_name);
-
- return g_string_free (xml_string, FALSE);
}
diff --git a/gdata/gdata-private.h b/gdata/gdata-private.h
index d2ad413..e92d887 100644
--- a/gdata/gdata-private.h
+++ b/gdata/gdata-private.h
@@ -41,7 +41,7 @@ GDataParsable *_gdata_parsable_new_from_xml (GType parsable_type, const gchar *x
GError **error) G_GNUC_WARN_UNUSED_RESULT;
GDataParsable *_gdata_parsable_new_from_xml_node (GType parsable_type, xmlDoc *doc, xmlNode *node, gpointer user_data,
GError **error) G_GNUC_WARN_UNUSED_RESULT;
-gchar *_gdata_parsable_get_xml (GDataParsable *self, gboolean declare_namespaces) G_GNUC_WARN_UNUSED_RESULT;
+void _gdata_parsable_get_xml (GDataParsable *self, GString *xml_string, gboolean declare_namespaces);
#include "gdata-feed.h"
GDataFeed *_gdata_feed_new_from_xml (GType feed_type, const gchar *xml, gint length, GType entry_type,
diff --git a/gdata/media/gdata-media-group.c b/gdata/media/gdata-media-group.c
index 778980b..f4004d3 100644
--- a/gdata/media/gdata-media-group.c
+++ b/gdata/media/gdata-media-group.c
@@ -263,11 +263,8 @@ get_xml (GDataParsable *parsable, GString *xml_string)
GDataMediaGroupPrivate *priv = GDATA_MEDIA_GROUP (parsable)->priv;
/* Media category */
- if (priv->category != NULL) {
- gchar *xml = _gdata_parsable_get_xml (GDATA_PARSABLE (priv->category), FALSE);
- g_string_append (xml_string, xml);
- g_free (xml);
- }
+ if (priv->category != NULL)
+ _gdata_parsable_get_xml (GDATA_PARSABLE (priv->category), xml_string, FALSE);
if (priv->title != NULL) {
gchar *title = g_markup_escape_text (priv->title, -1);
diff --git a/gdata/services/calendar/gdata-calendar-event.c b/gdata/services/calendar/gdata-calendar-event.c
index c802091..0261100 100644
--- a/gdata/services/calendar/gdata-calendar-event.c
+++ b/gdata/services/calendar/gdata-calendar-event.c
@@ -607,11 +607,8 @@ get_child_xml (GList *list, GString *xml_string)
{
GList *i;
- for (i = list; i != NULL; i = i->next) {
- gchar *xml = _gdata_parsable_get_xml (GDATA_PARSABLE (i->data), FALSE);
- g_string_append (xml_string, xml);
- g_free (xml);
- }
+ for (i = list; i != NULL; i = i->next)
+ _gdata_parsable_get_xml (GDATA_PARSABLE (i->data), xml_string, FALSE);
}
static void
diff --git a/gdata/services/contacts/gdata-contacts-contact.c b/gdata/services/contacts/gdata-contacts-contact.c
index 3e5671c..bfae3a9 100644
--- a/gdata/services/contacts/gdata-contacts-contact.c
+++ b/gdata/services/contacts/gdata-contacts-contact.c
@@ -374,11 +374,8 @@ get_child_xml (GList *list, GString *xml_string)
{
GList *i;
- for (i = list; i != NULL; i = i->next) {
- gchar *xml = _gdata_parsable_get_xml (GDATA_PARSABLE (i->data), FALSE);
- g_string_append (xml_string, xml);
- g_free (xml);
- }
+ for (i = list; i != NULL; i = i->next)
+ _gdata_parsable_get_xml (GDATA_PARSABLE (i->data), xml_string, FALSE);
}
static void
diff --git a/gdata/services/picasaweb/gdata-picasaweb-album.c b/gdata/services/picasaweb/gdata-picasaweb-album.c
index dd4e2cb..2ee3e68 100644
--- a/gdata/services/picasaweb/gdata-picasaweb-album.c
+++ b/gdata/services/picasaweb/gdata-picasaweb-album.c
@@ -601,7 +601,6 @@ parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_da
static void
get_xml (GDataParsable *parsable, GString *xml_string)
{
- gchar *xml;
GDataPicasaWebAlbumPrivate *priv = GDATA_PICASAWEB_ALBUM (parsable)->priv;
/* Chain up to the parent class */
@@ -634,9 +633,7 @@ get_xml (GDataParsable *parsable, GString *xml_string)
g_string_append (xml_string, "<gphoto:commentingEnabled>true</gphoto:commentingEnabled>");
/* media:group */
- xml = _gdata_parsable_get_xml (GDATA_PARSABLE (priv->media_group), FALSE);
- g_string_append (xml_string, xml);
- g_free (xml);
+ _gdata_parsable_get_xml (GDATA_PARSABLE (priv->media_group), xml_string, FALSE);
/* TODO: add GML support */
/* TODO:
diff --git a/gdata/services/picasaweb/gdata-picasaweb-file.c b/gdata/services/picasaweb/gdata-picasaweb-file.c
index c42adb9..e683b72 100644
--- a/gdata/services/picasaweb/gdata-picasaweb-file.c
+++ b/gdata/services/picasaweb/gdata-picasaweb-file.c
@@ -686,7 +686,6 @@ parse_xml (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_da
static void
get_xml (GDataParsable *parsable, GString *xml_string)
{
- gchar *xml;
GDataPicasaWebFilePrivate *priv = GDATA_PICASAWEB_FILE (parsable)->priv;
/* Chain up to the parent class */
@@ -728,9 +727,7 @@ get_xml (GDataParsable *parsable, GString *xml_string)
g_string_append_printf (xml_string, "<gphoto:rotation>%u</gphoto:rotation>", priv->rotation);
/* media:group */
- xml = _gdata_parsable_get_xml (GDATA_PARSABLE (priv->media_group), FALSE);
- g_string_append (xml_string, xml);
- g_free (xml);
+ _gdata_parsable_get_xml (GDATA_PARSABLE (priv->media_group), xml_string, FALSE);
/* TODO:
* - Finish supporting all tags
diff --git a/gdata/services/youtube/gdata-youtube-video.c b/gdata/services/youtube/gdata-youtube-video.c
index d8e8fd6..4a262fe 100644
--- a/gdata/services/youtube/gdata-youtube-video.c
+++ b/gdata/services/youtube/gdata-youtube-video.c
@@ -759,16 +759,13 @@ post_parse_xml (GDataParsable *parsable, gpointer user_data, GError **error)
static void
get_xml (GDataParsable *parsable, GString *xml_string)
{
- gchar *xml;
GDataYouTubeVideoPrivate *priv = GDATA_YOUTUBE_VIDEO (parsable)->priv;
/* Chain up to the parent class */
GDATA_PARSABLE_CLASS (gdata_youtube_video_parent_class)->get_xml (parsable, xml_string);
/* media:group */
- xml = _gdata_parsable_get_xml (GDATA_PARSABLE (priv->media_group), FALSE);
- g_string_append (xml_string, xml);
- g_free (xml);
+ _gdata_parsable_get_xml (GDATA_PARSABLE (priv->media_group), xml_string, FALSE);
if (priv->location != NULL) {
gchar *location = g_markup_escape_text (priv->location, -1);
@@ -786,9 +783,7 @@ get_xml (GDataParsable *parsable, GString *xml_string)
g_string_append (xml_string, "<yt:noembed/>");
/* app:control */
- xml = _gdata_parsable_get_xml (GDATA_PARSABLE (priv->youtube_control), FALSE);
- g_string_append (xml_string, xml);
- g_free (xml);
+ _gdata_parsable_get_xml (GDATA_PARSABLE (priv->youtube_control), xml_string, FALSE);
/* TODO:
* - georss:where
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]