summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Feltman <sfeltman@src.gnome.org>2014-09-11 17:17:45 -0700
committerColin Walters <walters@verbum.org>2015-10-19 18:24:43 -0400
commitaa4f3f5045f2952d4004bc1c7d7e076d1de03fdc (patch)
tree4a42d04bbbd59e965a4d268d9d75865e6eb0a5fe
parentcf713559de494229d6104bd98883f49c0ff1f663 (diff)
downloadgobject-introspection-aa4f3f5045f2952d4004bc1c7d7e076d1de03fdc.tar.gz
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
-rw-r--r--tests/scanner/regress.c48
1 files changed, 26 insertions, 22 deletions
diff --git a/tests/scanner/regress.c b/tests/scanner/regress.c
index c05bae29..9a9ee679 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;
}