[gtk/strdup-avoidance: 1/3] shortcutaction: Intern signal names




commit 6136f3ab954b1bdafd3da8fbe594e6cdc39a6293
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Aug 27 22:33:21 2022 -0400

    shortcutaction: Intern signal names
    
    Signal names are already interned anyway,
    so we can avoid strdups here, and just use
    the interned names.

 gtk/gtkshortcutaction.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkshortcutaction.c b/gtk/gtkshortcutaction.c
index 8239b0916c..ccb46e327d 100644
--- a/gtk/gtkshortcutaction.c
+++ b/gtk/gtkshortcutaction.c
@@ -595,7 +595,7 @@ struct _GtkSignalAction
 {
   GtkShortcutAction parent_instance;
 
-  char *name;
+  const char *name; /* interned */
 };
 
 struct _GtkSignalActionClass
@@ -616,9 +616,7 @@ G_DEFINE_TYPE (GtkSignalAction, gtk_signal_action, GTK_TYPE_SHORTCUT_ACTION)
 static void
 gtk_signal_action_finalize (GObject *gobject)
 {
-  GtkSignalAction *self = GTK_SIGNAL_ACTION (gobject);
-
-  g_free (self->name);
+  //GtkSignalAction *self = GTK_SIGNAL_ACTION (gobject);
 
   G_OBJECT_CLASS (gtk_signal_action_parent_class)->finalize (gobject);
 }
@@ -899,7 +897,7 @@ gtk_signal_action_set_property (GObject      *gobject,
   switch (prop_id)
     {
     case SIGNAL_PROP_SIGNAL_NAME:
-      self->name = g_value_dup_string (value);
+      self->name = g_intern_string (g_value_get_string (value));
       break;
 
     default:
@@ -974,11 +972,21 @@ gtk_signal_action_init (GtkSignalAction *self)
 GtkShortcutAction *
 gtk_signal_action_new (const char *signal_name)
 {
+  GtkShortcutAction *action;
+  const char *name = "signal-name";
+  GValue value = G_VALUE_INIT;
+
   g_return_val_if_fail (signal_name != NULL, NULL);
 
-  return g_object_new (GTK_TYPE_SIGNAL_ACTION,
-                       "signal-name", signal_name,
-                       NULL);
+  g_value_init (&value, G_TYPE_STRING);
+  g_value_set_static_string (&value, signal_name);
+
+  action = GTK_SHORTCUT_ACTION (g_object_new_with_properties (GTK_TYPE_SIGNAL_ACTION,
+                                                              1, &name, &value));
+
+  g_value_unset (&value);
+
+  return action;
 }
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]