[gobject-introspection] tests: Usage a single allocation for test_ghash_gvalue_return



commit aa4f3f5045f2952d4004bc1c7d7e076d1de03fdc
Author: Simon Feltman <sfeltman src gnome org>
Date:   Thu Sep 11 17:17:45 2014 -0700

    tests: Usage a single allocation for test_ghash_gvalue_return
    
    Use a single static allocation for the hash created in regress_test_ghash_gvalue_return().
    This function is explicitly marked as returning the hash with transfer-none
    and doesn't need to re-create the hash each call.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=736517

 tests/scanner/regress.c |   48 +++++++++++++++++++++++++---------------------
 1 files changed, 26 insertions(+), 22 deletions(-)
---
diff --git a/tests/scanner/regress.c b/tests/scanner/regress.c
index c05bae2..9a9ee67 100644
--- a/tests/scanner/regress.c
+++ b/tests/scanner/regress.c
@@ -1299,34 +1299,38 @@ static const gchar *string_array[] = {
 GHashTable *
 regress_test_ghash_gvalue_return (void)
 {
-  GHashTable *hash;
-  GValue *value;
-  hash = g_hash_table_new_full(g_str_hash, g_str_equal,
-                               g_free, (GDestroyNotify)g_value_free);
+  static GHashTable *hash = NULL;
 
-  value = g_value_new(G_TYPE_INT);
-  g_value_set_int(value, 12);
-  g_hash_table_insert(hash, g_strdup("integer"), value);
+  if (hash == NULL)
+    {
+      GValue *value;
+      hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+                                   g_free, (GDestroyNotify)g_value_free);
+
+      value = g_value_new(G_TYPE_INT);
+      g_value_set_int(value, 12);
+      g_hash_table_insert(hash, g_strdup("integer"), value);
 
-  value = g_value_new(G_TYPE_BOOLEAN);
-  g_value_set_boolean(value, TRUE);
-  g_hash_table_insert(hash, g_strdup("boolean"), value);
+      value = g_value_new(G_TYPE_BOOLEAN);
+      g_value_set_boolean(value, TRUE);
+      g_hash_table_insert(hash, g_strdup("boolean"), value);
 
-  value = g_value_new(G_TYPE_STRING);
-  g_value_set_string(value, "some text");
-  g_hash_table_insert(hash, g_strdup("string"), value);
+      value = g_value_new(G_TYPE_STRING);
+      g_value_set_string(value, "some text");
+      g_hash_table_insert(hash, g_strdup("string"), value);
 
-  value = g_value_new(G_TYPE_STRV);
-  g_value_set_boxed(value, string_array);
-  g_hash_table_insert(hash, g_strdup("strings"), value);
+      value = g_value_new(G_TYPE_STRV);
+      g_value_set_boxed(value, string_array);
+      g_hash_table_insert(hash, g_strdup("strings"), value);
 
-  value = g_value_new(REGRESS_TEST_TYPE_FLAGS);
-  g_value_set_flags(value, REGRESS_TEST_FLAG1 | REGRESS_TEST_FLAG3);
-  g_hash_table_insert(hash, g_strdup("flags"), value);
+      value = g_value_new(REGRESS_TEST_TYPE_FLAGS);
+      g_value_set_flags(value, REGRESS_TEST_FLAG1 | REGRESS_TEST_FLAG3);
+      g_hash_table_insert(hash, g_strdup("flags"), value);
 
-  value = g_value_new(regress_test_enum_get_type());
-  g_value_set_enum(value, REGRESS_TEST_VALUE2);
-  g_hash_table_insert(hash, g_strdup("enum"), value);
+      value = g_value_new(regress_test_enum_get_type());
+      g_value_set_enum(value, REGRESS_TEST_VALUE2);
+      g_hash_table_insert(hash, g_strdup("enum"), value);
+    }
 
   return hash;
 }


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