[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] Functions much easier to use than apr_hash_this()

From: Julian Foad <julianfoad_at_btopenworld.com>
Date: Thu, 09 Jul 2009 18:30:16 +0100

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

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2369457

Received on 2009-07-09 19:30:45 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.