summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-11-17 14:02:47 +0000
committerRichard Hughes <richard@hughsie.com>2016-11-18 20:22:31 +0000
commit9d8cec9a4a4e955f4267acd1a016801fbdff2f80 (patch)
tree107f26c55286d51e32b0db478c137a47b7d635e1
parent486872098e4445ceeae4fad900072f4e1969f8ad (diff)
downloadappstream-glib-9d8cec9a4a4e955f4267acd1a016801fbdff2f80.tar.gz
Lazy load the screenshot captions storage
This saves 0.8Mb RSS when using the Fedora AppStream file.
-rw-r--r--libappstream-glib/as-screenshot.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/libappstream-glib/as-screenshot.c b/libappstream-glib/as-screenshot.c
index 3a03d3c..65ce4e7 100644
--- a/libappstream-glib/as-screenshot.c
+++ b/libappstream-glib/as-screenshot.c
@@ -60,7 +60,8 @@ as_screenshot_finalize (GObject *object)
AsScreenshotPrivate *priv = GET_PRIVATE (screenshot);
g_ptr_array_unref (priv->images);
- g_hash_table_unref (priv->captions);
+ if (priv->captions != NULL)
+ g_hash_table_unref (priv->captions);
G_OBJECT_CLASS (as_screenshot_parent_class)->finalize (object);
}
@@ -71,6 +72,14 @@ as_screenshot_init (AsScreenshot *screenshot)
AsScreenshotPrivate *priv = GET_PRIVATE (screenshot);
priv->kind = AS_SCREENSHOT_KIND_NORMAL;
priv->images = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
+}
+
+static void
+as_screenshot_ensure_captions (AsScreenshot *screenshot)
+{
+ AsScreenshotPrivate *priv = GET_PRIVATE (screenshot);
+ if (priv->captions != NULL)
+ return;
priv->captions = g_hash_table_new_full (g_str_hash,
g_str_equal,
(GDestroyNotify) as_ref_string_unref,
@@ -317,6 +326,8 @@ const gchar *
as_screenshot_get_caption (AsScreenshot *screenshot, const gchar *locale)
{
AsScreenshotPrivate *priv = GET_PRIVATE (screenshot);
+ if (priv->captions == NULL)
+ return NULL;
return as_hash_lookup_by_locale (priv->captions, locale);
}
@@ -386,6 +397,7 @@ as_screenshot_set_caption (AsScreenshot *screenshot,
AsScreenshotPrivate *priv = GET_PRIVATE (screenshot);
if (locale == NULL)
locale = "C";
+ as_screenshot_ensure_captions (screenshot);
g_hash_table_insert (priv->captions,
as_ref_string_new (locale),
as_ref_string_new (caption));
@@ -425,10 +437,12 @@ as_screenshot_node_insert (AsScreenshot *screenshot,
as_screenshot_kind_to_string (priv->kind));
}
if (as_node_context_get_version (ctx) >= 0.41) {
- as_node_insert_localized (n,
- "caption",
- priv->captions,
- AS_NODE_INSERT_FLAG_DEDUPE_LANG);
+ if (priv->captions != NULL) {
+ as_node_insert_localized (n,
+ "caption",
+ priv->captions,
+ AS_NODE_INSERT_FLAG_DEDUPE_LANG);
+ }
}
if (as_node_context_get_version (ctx) >= 0.8 && priv->priority != 0)
as_node_add_attribute_as_int (n, "priority", priv->priority);