subversion-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Philip Martin <philip.mar...@wandisco.com>
Subject 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
Date Mon, 10 Oct 2011 10:48:58 GMT
pburba@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

Mime
View raw message