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

Re: svn commit: r1180154 - in /subversion/trunk/subversion: include/svn_sorts.h libsvn_client/merge.c libsvn_subr/mergeinfo.c libsvn_subr/sorts.c tests/libsvn_subr/mergeinfo-test.c

From: Philip Martin <philip.martin_at_wandisco.com>
Date: Mon, 10 Oct 2011 11:48:58 +0100

pburba_at_apache.org writes:

> Author: pburba
> Date: Fri Oct 7 19:00:40 2011
> New Revision: 1180154

> + if (elements_to_delete)
> + for (i = starting_index; i < (elements_to_delete + starting_index); i++)
> + svn_sort__array_delete(rangelist, starting_index);
> +}

Given the pop optimisation it would be more efficient to delete the
elements in reverse order. Passing the number of elements to be deleted
to svn_sort__array_delete would be better.

> +void
> +svn_sort__array_delete(apr_array_header_t *arr,
> + int delete_index)
> +{
> + /* Do we have a valid index? */
> + if (delete_index >= 0 && delete_index < arr->nelts)
> + {
> + if (delete_index == (arr->nelts - 1))
> + {
> + /* Deleting the last or only element in an array is easy. */
> + apr_array_pop(arr);
> + }
> + else
> + {
> + memmove(arr->elts + arr->elt_size * delete_index,
> + arr->elts + arr->elt_size * (delete_index + 1),
> + arr->elt_size * (arr->nelts - 1 - delete_index));
> + --(arr->nelts);
> + }
> + }
> +}

-- 
Philip
Received on 2011-10-10 12:49:39 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.