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

Re: Convenient array & hash iterators & accessors

From: Greg Stein <gstein_at_gmail.com>
Date: Fri, 6 Mar 2015 02:08:29 -0600

We've seen some of this kind of stuff in svn_iter.h, and it did not turn
out to be useful. The additional concepts needed to learn/keep/use costed
more than the incremental benefit.

I find the SVN_ITER_T() and SVN_ARRAY_ITER() macros in your example to be
rather inscrutable.

Cheers,
-g

On Thu, Mar 5, 2015 at 6:16 AM, Julian Foad <julianfoad_at_btopenworld.com>
wrote:

> In http://svn.apache.org/r1664127 (very similar to the attached patch),
> I added some array & hash iterators & accessors to the 'move-tracking-2'
> branch
> so that I could use more compact iteration code (
> http://svn.apache.org/r1664285)
> and get an iteration pool 'for free' (http://svn.apache.org/r1664290).
>
> Is there any interest in using some of this on trunk?
>
> Here's a summary.
>
> Array: apr_array_header_t of pointers to objects, with
>
> - Simpler syntax for operations such as make, get, set, push, pop.
>
> - no need to specify the element type in these operations
>
> - The get and set and iteration functions avoid the need to use the
> non-type-safe APR_ARRAY_IDX. (It does not assert that the sizeof(type)
> matches, let alone (type) itself. Note: When I inserted
> "assert(sizeof(type)==array->elt_size)" in APR's version, the
> Subversion
> test suite still passed, so that's good.)
>
> - Shallow and deep duplicators for an array of simple or compound
> elements.
>
> Hash table: same as apr_hash_t but always with C-string keys.
>
> Iteration over an array or a hash shares these features:
>
> - Convenience prioritized over speed (but still good speed).
>
> - Easy access to this key and this value as iterator member variables.
>
> - for an array: it->i and it->val
> - for a hash: it->key and it->val (and it->klen for good measure)
>
> - Templated iterator with parameterized element type.
>
> - in an iterator declared as "SVN_ITER_T(svn_branch_family_t) *it;",
> it->val has type "svn_branch_family_t *"
>
> - in an iterator declared as "svn_iter_t *it;",
> it->val has type "void *"
>
> - Built-in, managed iterpool as an iterator member variable.
>
> - just use it->iterpool; it is automatically created/cleared/destroyed
>
> - Iteration in sorted order (optional).
>
> - just use "for (SVN_ARRAY_ITER_SORTED(it, array, comparator, pool))"
> instead of "for (SVN_ARRAY_ITER(it, array, pool))"; same for a hash
>
> Usage examples:
>
> - outer_family->sub_families = apr_array_make(result_pool, 1, sizeof(void
> *));
> + outer_family->sub_families = svn_array_make(result_pool);
>
> - APR_ARRAY_PUSH(outer_family->sub_families, void *) = family;
> + SVN_ARRAY_PUSH(outer_family->sub_families) = family;
>
> {
> - apr_array_header_t *sub_families
> - = svn_branch_family_get_children(family, scratch_pool);
> - int f;
> + SVN_ITER_T(svn_branch_family_t) *fi;
>
> - for (f = 0; f < sub_families->nelts; f++)
> + for (SVN_ARRAY_ITER(fi, svn_branch_family_get_children(
> + family, scratch_pool), scratch_pool))
> {
> - svn_branch_family_t *sub_family
> - = APR_ARRAY_IDX(sub_families, f, svn_branch_family_t *);
> -
> - SVN_ERR(family_list_branch_instances(rev_root, sub_family,
> recursive,
> + SVN_ERR(family_list_branch_instances(rev_root, fi->val, recursive,
> - verbose, scratch_pool));
> - verbose, fi->iterpool));
> }
> }
>
> - Julian
>
Received on 2015-03-06 09:08:56 CET

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