summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-04-30 15:15:34 +0200
committerThomas Haller <thaller@redhat.com>2015-06-17 10:54:56 +0200
commit2bea70e75031bad941f0e9562bd2293f72b0e277 (patch)
treec50e3bac4c332f645ba3ad865a8372ef7edc3779 /include
parent64d918293bdf3e16c8a53d4146a5343ec6c9ffee (diff)
downloadNetworkManager-2bea70e75031bad941f0e9562bd2293f72b0e277.tar.gz
glib-compat: add nm_g_hash_table_replace() compat function
The newer version of g_hash_table_replace() is useful, because it saves an additional hash table lookup.
Diffstat (limited to 'include')
-rw-r--r--include/nm-glib-compat.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/include/nm-glib-compat.h b/include/nm-glib-compat.h
index 1dc939feac..c5674ea9e7 100644
--- a/include/nm-glib-compat.h
+++ b/include/nm-glib-compat.h
@@ -163,4 +163,21 @@ q_n##_quark (void) \
}
#endif
+
+static inline gboolean
+nm_g_hash_table_replace (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_replace (hash, key, value);
+#else
+ gboolean contained = g_hash_table_contains (hash, key);
+
+ g_hash_table_replace (hash, key, value);
+ return !contained;
+#endif
+}
+
+
#endif /* __NM_GLIB_COMPAT_H__ */