From 6782a91adeb876dddb7501d00ed51eb9ce75d6eb Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Fri, 18 May 2018 15:06:53 +0100 Subject: trivial: Do not reallocate all the AsImage URL strings --- libappstream-glib/as-image-private.h | 2 ++ libappstream-glib/as-image.c | 7 +++++++ libappstream-glib/as-screenshot.c | 7 ++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libappstream-glib/as-image-private.h b/libappstream-glib/as-image-private.h index 47f98c7..927cbe7 100644 --- a/libappstream-glib/as-image-private.h +++ b/libappstream-glib/as-image-private.h @@ -42,6 +42,8 @@ gboolean as_image_node_parse_dep11 (AsImage *image, GNode *node, AsNodeContext *ctx, GError **error); +void as_image_set_url_rstr (AsImage *image, + AsRefString *rstr); G_END_DECLS diff --git a/libappstream-glib/as-image.c b/libappstream-glib/as-image.c index 6949e71..5b6f1f9 100644 --- a/libappstream-glib/as-image.c +++ b/libappstream-glib/as-image.c @@ -281,6 +281,13 @@ as_image_set_url (AsImage *image, const gchar *url) as_ref_string_assign_safe (&priv->url, url); } +void +as_image_set_url_rstr (AsImage *image, AsRefString *rstr) +{ + AsImagePrivate *priv = GET_PRIVATE (image); + as_ref_string_assign (&priv->url, rstr); +} + /** * as_image_set_basename: * @image: a #AsImage instance. diff --git a/libappstream-glib/as-screenshot.c b/libappstream-glib/as-screenshot.c index ab8cb92..1e479f3 100644 --- a/libappstream-glib/as-screenshot.c +++ b/libappstream-glib/as-screenshot.c @@ -469,6 +469,7 @@ as_screenshot_node_parse (AsScreenshot *screenshot, GNode *node, AsNodeContext *ctx, GError **error) { AsScreenshotPrivate *priv = GET_PRIVATE (screenshot); + AsRefString *str; GList *l; GNode *c; const gchar *tmp; @@ -499,8 +500,8 @@ as_screenshot_node_parse (AsScreenshot *screenshot, GNode *node, } /* AppData files does not have tags */ - tmp = as_node_get_data (node); - if (tmp != NULL) { + str = as_node_get_data_as_refstr (node); + if (str != NULL) { AsImage *image; image = as_image_new (); as_image_set_kind (image, AS_IMAGE_KIND_SOURCE); @@ -510,7 +511,7 @@ as_screenshot_node_parse (AsScreenshot *screenshot, GNode *node, size = as_node_get_attribute_as_uint (node, "height"); if (size != G_MAXUINT) as_image_set_height (image, size); - as_image_set_url (image, tmp); + as_image_set_url_rstr (image, str); g_ptr_array_add (priv->images, image); } -- cgit v1.2.1