summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Pazdziora <jpazdziora@redhat.com>2014-05-12 14:52:08 +0200
committerJan Pazdziora <jpazdziora@redhat.com>2014-05-13 09:17:36 +0200
commit8bc874ad1a9b5df6e3d5a4987c86d7826d1f88ad (patch)
treec90724f4b053ea7dc314428cf29c72da9ca95b5c
parent72e47a7644459df40ea68ed5fc28444d9ed8a9b7 (diff)
downloadmod_lookup_identity-8bc874ad1a9b5df6e3d5a4987c86d7826d1f88ad.tar.gz
mod_lookup_identity-8bc874ad1a9b5df6e3d5a4987c86d7826d1f88ad.tar.xz
mod_lookup_identity-8bc874ad1a9b5df6e3d5a4987c86d7826d1f88ad.zip
apr_hash_count can be used to get the number of keys instead of looping.
-rw-r--r--mod_lookup_identity.c18
1 files 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) {