mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-17 12:30:28 +01:00
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.
(cherry picked from commit 2bea70e750)
This commit is contained in:
parent
fa7acaef83
commit
a87231abbc
1 changed files with 17 additions and 0 deletions
|
|
@ -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__ */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue