Intern type names before registering the type to avoid unnecessary copies.
[platform/upstream/glib.git] / gobject / gvaluetypes.c
index 4822786..cb3de7e 100644 (file)
@@ -24,6 +24,7 @@
 #include       "gvaluetypes.h"
 
 #include       "gvaluecollector.h"
+#include       "gobjectalias.h"
 #include       <string.h>
 #include       <stdlib.h>      /* qsort() */
 
@@ -357,7 +358,7 @@ value_lcopy_pointer (const GValue *value,
 
 /* --- type initialization --- */
 void
-g_value_types_init (void)  /* sync with gtype.c */
+g_value_types_init (void)
 {
   GTypeInfo info = {
     0,                         /* class_size */
@@ -388,9 +389,9 @@ g_value_types_init (void)  /* sync with gtype.c */
       value_lcopy_char,                /* lcopy_value */
     };
     info.value_table = &value_table;
-    type = g_type_register_fundamental (G_TYPE_CHAR, "gchar", &info, &finfo, 0);
+    type = g_type_register_fundamental (G_TYPE_CHAR, g_intern_static_string ("gchar"), &info, &finfo, 0);
     g_assert (type == G_TYPE_CHAR);
-    type = g_type_register_fundamental (G_TYPE_UCHAR, "guchar", &info, &finfo, 0);
+    type = g_type_register_fundamental (G_TYPE_UCHAR, g_intern_static_string ("guchar"), &info, &finfo, 0);
     g_assert (type == G_TYPE_UCHAR);
   }
 
@@ -408,7 +409,7 @@ g_value_types_init (void)  /* sync with gtype.c */
       value_lcopy_boolean,      /* lcopy_value */
     };
     info.value_table = &value_table;
-    type = g_type_register_fundamental (G_TYPE_BOOLEAN, "gboolean", &info, &finfo, 0);
+    type = g_type_register_fundamental (G_TYPE_BOOLEAN, g_intern_static_string ("gboolean"), &info, &finfo, 0);
     g_assert (type == G_TYPE_BOOLEAN);
   }
   
@@ -426,9 +427,9 @@ g_value_types_init (void)  /* sync with gtype.c */
       value_lcopy_int,         /* lcopy_value */
     };
     info.value_table = &value_table;
-    type = g_type_register_fundamental (G_TYPE_INT, "gint", &info, &finfo, 0);
+    type = g_type_register_fundamental (G_TYPE_INT, g_intern_static_string ("gint"), &info, &finfo, 0);
     g_assert (type == G_TYPE_INT);
-    type = g_type_register_fundamental (G_TYPE_UINT, "guint", &info, &finfo, 0);
+    type = g_type_register_fundamental (G_TYPE_UINT, g_intern_static_string ("guint"), &info, &finfo, 0);
     g_assert (type == G_TYPE_UINT);
   }
 
@@ -446,9 +447,9 @@ g_value_types_init (void)  /* sync with gtype.c */
       value_lcopy_long,                /* lcopy_value */
     };
     info.value_table = &value_table;
-    type = g_type_register_fundamental (G_TYPE_LONG, "glong", &info, &finfo, 0);
+    type = g_type_register_fundamental (G_TYPE_LONG, g_intern_static_string ("glong"), &info, &finfo, 0);
     g_assert (type == G_TYPE_LONG);
-    type = g_type_register_fundamental (G_TYPE_ULONG, "gulong", &info, &finfo, 0);
+    type = g_type_register_fundamental (G_TYPE_ULONG, g_intern_static_string ("gulong"), &info, &finfo, 0);
     g_assert (type == G_TYPE_ULONG);
   }
   
@@ -466,9 +467,9 @@ g_value_types_init (void)  /* sync with gtype.c */
       value_lcopy_int64,       /* lcopy_value */
     };
     info.value_table = &value_table;
-    type = g_type_register_fundamental (G_TYPE_INT64, "gint64", &info, &finfo, 0);
+    type = g_type_register_fundamental (G_TYPE_INT64, g_intern_static_string ("gint64"), &info, &finfo, 0);
     g_assert (type == G_TYPE_INT64);
-    type = g_type_register_fundamental (G_TYPE_UINT64, "guint64", &info, &finfo, 0);
+    type = g_type_register_fundamental (G_TYPE_UINT64, g_intern_static_string ("guint64"), &info, &finfo, 0);
     g_assert (type == G_TYPE_UINT64);
   }
   
@@ -486,7 +487,7 @@ g_value_types_init (void)  /* sync with gtype.c */
       value_lcopy_float,        /* lcopy_value */
     };
     info.value_table = &value_table;
-    type = g_type_register_fundamental (G_TYPE_FLOAT, "gfloat", &info, &finfo, 0);
+    type = g_type_register_fundamental (G_TYPE_FLOAT, g_intern_static_string ("gfloat"), &info, &finfo, 0);
     g_assert (type == G_TYPE_FLOAT);
   }
   
@@ -504,7 +505,7 @@ g_value_types_init (void)  /* sync with gtype.c */
       value_lcopy_double,      /* lcopy_value */
     };
     info.value_table = &value_table;
-    type = g_type_register_fundamental (G_TYPE_DOUBLE, "gdouble", &info, &finfo, 0);
+    type = g_type_register_fundamental (G_TYPE_DOUBLE, g_intern_static_string ("gdouble"), &info, &finfo, 0);
     g_assert (type == G_TYPE_DOUBLE);
   }
 
@@ -522,7 +523,7 @@ g_value_types_init (void)  /* sync with gtype.c */
       value_lcopy_string,      /* lcopy_value */
     };
     info.value_table = &value_table;
-    type = g_type_register_fundamental (G_TYPE_STRING, "gchararray", &info, &finfo, 0);
+    type = g_type_register_fundamental (G_TYPE_STRING, g_intern_static_string ("gchararray"), &info, &finfo, 0);
     g_assert (type == G_TYPE_STRING);
   }
 
@@ -540,7 +541,7 @@ g_value_types_init (void)  /* sync with gtype.c */
       value_lcopy_pointer,     /* lcopy_value */
     };
     info.value_table = &value_table;
-    type = g_type_register_fundamental (G_TYPE_POINTER, "gpointer", &info, &finfo, 0);
+    type = g_type_register_fundamental (G_TYPE_POINTER, g_intern_static_string ("gpointer"), &info, &finfo, 0);
     g_assert (type == G_TYPE_POINTER);
   }
 }
@@ -738,13 +739,18 @@ void
 g_value_set_string (GValue     *value,
                    const gchar *v_string)
 {
+  gchar *new_val;
+
   g_return_if_fail (G_VALUE_HOLDS_STRING (value));
-  
+
+  new_val = g_strdup (v_string);
+
   if (value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS)
     value->data[1].v_uint = 0;
   else
     g_free (value->data[0].v_pointer);
-  value->data[0].v_pointer = g_strdup (v_string);
+
+  value->data[0].v_pointer = new_val;
 }
 
 void
@@ -905,3 +911,5 @@ g_pointer_type_register_static (const gchar *name)
   return type;
 }
 
+#define __G_VALUETYPES_C__
+#include "gobjectaliasdef.c"