summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-04-30 15:15:34 +0200
committerThomas Haller <thaller@redhat.com>2015-05-06 12:33:28 +0200
commit4d56e895fed1bec24d0ba523caeef4ceea86e5fa (patch)
tree5ddd692e9ee77d79aeda65387a2f612a19d0eb51
parentcd8809c48a383cbfd69f0bbfe74749caf8334ec9 (diff)
downloadNetworkManager-4d56e895fed1bec24d0ba523caeef4ceea86e5fa.tar.gz
glib-compat: add nm_g_hash_table_replace() compat function
The newer version of g_hash_table_replace() is neat, because it saves an additional hash table lookup.
-rw-r--r--include/nm-glib-compat.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/include/nm-glib-compat.h b/include/nm-glib-compat.h
index 639386ead9..5aeabdeaf6 100644
--- a/include/nm-glib-compat.h
+++ b/include/nm-glib-compat.h
@@ -195,4 +195,20 @@ _nm_g_ptr_array_insert (GPtrArray *array,
#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__ */