[libdazzle] suggestion: avoid string duplications of icon names
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libdazzle] suggestion: avoid string duplications of icon names
- Date: Mon, 4 Sep 2017 00:20:31 +0000 (UTC)
commit 6abe19cab041950a1b23a8d30942fd6427815ce0
Author: Christian Hergert <chergert redhat com>
Date: Sun Sep 3 17:20:20 2017 -0700
suggestion: avoid string duplications of icon names
These are used a lot, no need to hold on to strings for them all in
memory when we almost certainly would have an interned string from
the icon cache anyway.
src/suggestions/dzl-suggestion.c | 14 ++++++++------
1 files changed, 8 insertions(+), 6 deletions(-)
---
diff --git a/src/suggestions/dzl-suggestion.c b/src/suggestions/dzl-suggestion.c
index ad256d7..791b0d1 100644
--- a/src/suggestions/dzl-suggestion.c
+++ b/src/suggestions/dzl-suggestion.c
@@ -24,8 +24,10 @@ typedef struct
{
gchar *title;
gchar *subtitle;
- gchar *icon_name;
gchar *id;
+
+ /* interned string */
+ const gchar *icon_name;
} DzlSuggestionPrivate;
enum {
@@ -56,7 +58,6 @@ dzl_suggestion_finalize (GObject *object)
g_clear_pointer (&priv->title, g_free);
g_clear_pointer (&priv->subtitle, g_free);
- g_clear_pointer (&priv->icon_name, g_free);
g_clear_pointer (&priv->id, g_free);
G_OBJECT_CLASS (dzl_suggestion_parent_class)->finalize (object);
@@ -77,7 +78,7 @@ dzl_suggestion_get_property (GObject *object,
break;
case PROP_ICON_NAME:
- g_value_set_string (value, dzl_suggestion_get_icon_name (self));
+ g_value_set_static_string (value, dzl_suggestion_get_icon_name (self));
break;
case PROP_TITLE:
@@ -233,10 +234,11 @@ dzl_suggestion_set_icon_name (DzlSuggestion *self,
g_return_if_fail (DZL_IS_SUGGESTION (self));
- if (g_strcmp0 (priv->icon_name, icon_name) != 0)
+ icon_name = g_intern_string (icon_name);
+
+ if (priv->icon_name != icon_name)
{
- g_free (priv->icon_name);
- priv->icon_name = g_strdup (icon_name);
+ priv->icon_name = icon_name;
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ICON_NAME]);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]