glib-compat: add compatibility function for g_hash_table_insert() and g_hash_table_add()

They have a different name, because we don't want to do the
extra work unless explicitly requested.
This commit is contained in:
Thomas Haller 2015-09-30 14:08:06 +02:00
parent df27e6d5fd
commit 261dff429e

View file

@ -185,6 +185,35 @@ nm_g_hash_table_replace (GHashTable *hash, gpointer key, gpointer value)
#endif
}
static inline gboolean
nm_g_hash_table_insert (GHashTable *hash, gpointer key, gpointer value)
{
/* glib 2.40 added a return value indicating whether the key already existed
* (910191597a6c2e5d5d460e9ce9efb4f47d9cc63c). */
#if GLIB_CHECK_VERSION(2, 40, 0)
return g_hash_table_insert (hash, key, value);
#else
gboolean contained = g_hash_table_contains (hash, key);
g_hash_table_insert (hash, key, value);
return !contained;
#endif
}
static inline gboolean
nm_g_hash_table_add (GHashTable *hash, gpointer key)
{
/* glib 2.40 added a return value indicating whether the key already existed
* (910191597a6c2e5d5d460e9ce9efb4f47d9cc63c). */
#if GLIB_CHECK_VERSION(2, 40, 0)
return g_hash_table_add (hash, key);
#else
gboolean contained = g_hash_table_contains (hash, key);
g_hash_table_add (hash, key);
return !contained;
#endif
}
#if !GLIB_CHECK_VERSION(2, 40, 0) || defined (NM_GLIB_COMPAT_H_TEST)
static inline void