From 8bc874ad1a9b5df6e3d5a4987c86d7826d1f88ad Mon Sep 17 00:00:00 2001 From: Jan Pazdziora Date: Mon, 12 May 2014 14:52:08 +0200 Subject: apr_hash_count can be used to get the number of keys instead of looping. --- mod_lookup_identity.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/mod_lookup_identity.c b/mod_lookup_identity.c index 785cec0..ae29509 100644 --- a/mod_lookup_identity.c +++ b/mod_lookup_identity.c @@ -80,21 +80,13 @@ static DBusMessage * lookup_identity_dbus_message(request_rec * r, DBusConnectio char * user = r->user; int nargs = 0; const char ** args = NULL; - if (hash) { + if (hash && (nargs = apr_hash_count(hash))) { apr_hash_index_t * hi = apr_hash_first(r->pool, hash); - while (hi) { - nargs++; - hi = apr_hash_next(hi); - } - if (nargs) { - args = apr_pcalloc(r->pool, nargs * sizeof(char *)); - hi = apr_hash_first(r->pool, hash); - int i; + args = apr_pcalloc(r->pool, nargs * sizeof(char *)); + for (int i = 0; hi; hi = apr_hash_next(hi), i++) { const void * ptr; - for (i = 0; hi; hi = apr_hash_next(hi), i++) { - apr_hash_this(hi, &ptr, NULL, NULL); - args[i] = ptr; - } + apr_hash_this(hi, &ptr, NULL, NULL); + args[i] = ptr; } } if (args) { -- cgit