apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Julian Foad <julianf...@btopenworld.com>
Subject [PATCH] Functions much easier to use than apr_hash_this()
Date Thu, 09 Jul 2009 17:30:16 GMT
The attached patch adds three functions for dereferencing an APR hash
index (iterator). The usage of apr_hash_this() can look something like:

  for (hi = apr_hash_first(pool, entries); hi; hi = apr_hash_next(hi))
    {
      const char *name;
      svn_wc_entry_t *wc_entry;
      const void *key;
      void *val;

      apr_hash_this(hi, &key, NULL, &val);
      name = key;
      wc_entry = val;

      ... (code that uses the key "name" and value "wc_entry") ...
    }

The reason for the temporary variables "key" and "val" is that you can't
pass pointers to the correct-type variables ("name" and "wc_entry") to
apr_hash_this() without getting pointer type warnings on typical
compilers.

With the attached patch, the above can be rewritten as:

  for (hi = apr_hash_first(pool, entries); hi; hi = apr_hash_next(hi))
    {
      const char *item = apr_hash_index_key(hi);
      svn_wc_entry_t *entry = apr_hash_index_val(hi);

      ... (code that uses the key "name" and value "wc_entry") ...
    }

We have just started using these functions (but with an additional
"svn_" prefix) in Subversion today, because the source code can then be
much cleaner.

I offer and recommend this patch for inclusion in APR. Please let me
know whether this is suitable or if there is anything I should do to
help get it in.

Thanks.
- Julian


Mime
View raw message