diff options
author | Jonathan Lebon <jlebon@redhat.com> | 2017-06-27 20:07:16 -0700 |
---|---|---|
committer | Jonathan Lebon <jlebon@redhat.com> | 2017-06-28 08:04:11 -0700 |
commit | 5ab15ac175ca45fce1b63a910f8ae2c488b92cfe (patch) | |
tree | 3816319bf7ec5b3f4a0bd5ab5d59ff77a787234e /glnx-macros.h | |
parent | 4d34066a2ff5d806db35c3ac765f87ace460fa7e (diff) | |
download | libglnx-5ab15ac175ca45fce1b63a910f8ae2c488b92cfe.tar.gz |
macros: add GLNX_HASH_TABLE_FOREACH_V
Looking at converting the ostree codebase, iterating over only the
values of a hash table (while ignoring the key) is actually a more
common pattern than I thought. So let's give it its own macro as well so
users don't have to resort to the _KV variant.
Diffstat (limited to 'glnx-macros.h')
-rw-r--r-- | glnx-macros.h | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/glnx-macros.h b/glnx-macros.h index cee068d..b5127b7 100644 --- a/glnx-macros.h +++ b/glnx-macros.h @@ -146,9 +146,10 @@ G_BEGIN_DECLS * All variables are scoped within the loop. You may use the `it` variable as * usual, e.g. to remove an element using g_hash_table_iter_remove(&it). There * are shorter variants for the more common cases where you do not need access - * to the iterator or to values: + * to the iterator or to keys/values: * * GLNX_HASH_TABLE_FOREACH (table, const char*, str) { ... } + * GLNX_HASH_TABLE_FOREACH_V (table, MyData*, data) { ... } * GLNX_HASH_TABLE_FOREACH_KV (table, const char*, str, MyData*, data) { ... } * */ @@ -163,6 +164,14 @@ G_BEGIN_DECLS _GLNX_MAKE_ANONYMOUS(_glnx_ht_iter_guard_), ht, \ _GLNX_MAKE_ANONYMOUS(_glnx_ht_iter_it_), kt, k, vt, v) +/* Variant of GLNX_HASH_TABLE_FOREACH_KV which omits unpacking keys. */ +#define GLNX_HASH_TABLE_FOREACH_V(ht, vt, v) \ + _GLNX_HASH_TABLE_FOREACH_IMPL_KV( \ + _GLNX_MAKE_ANONYMOUS(_glnx_ht_iter_guard_), ht, \ + _GLNX_MAKE_ANONYMOUS(_glnx_ht_iter_it_), \ + gpointer, _GLNX_MAKE_ANONYMOUS(_glnx_ht_iter_v_), \ + vt, v) + /* Variant of GLNX_HASH_TABLE_FOREACH_KV which omits unpacking vals. */ #define GLNX_HASH_TABLE_FOREACH(ht, kt, k) \ _GLNX_HASH_TABLE_FOREACH_IMPL_KV( \ |