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

Re: svn commit: r1445980 - /subversion/trunk/subversion/libsvn_subr/sorts.c

From: Julian Foad <julianfoad_at_btopenworld.com>
Date: Thu, 14 Feb 2013 01:19:49 +0000 (GMT)

> URL: http://svn.apache.org/r1445980

> Log:
> * subversion/libsvn_subr/sorts.c
>   (svn_sort__array_reverse): Replace a debug-only assertion with an
>     implementation for non pointer sized array items, which I hope
>     we never need. [...]

Thanks for prioviding an implementation.  I updated the doc string for you in r1446012.

- Julian

> Modified: subversion/trunk/subversion/libsvn_subr/sorts.c
> ==============================================================================
> --- subversion/trunk/subversion/libsvn_subr/sorts.c (original)
> +++ subversion/trunk/subversion/libsvn_subr/sorts.c Wed Feb 13 23:22:20 2013
> @@ -277,15 +277,32 @@ svn_sort__array_reverse(apr_array_header
> {
>   int i;
>
> -  assert(array->elt_size == sizeof(void *));
> +  if (array->elt_size == sizeof(void *))
> +    {
> +      for (i = 0; i < array->nelts / 2; i++)
> +        {
> +          int swap_index = array->nelts - i - 1;
> +          void *tmp = APR_ARRAY_IDX(array, i, void *);
>
> -  for (i = 0; i < array->nelts / 2; i++)
> +          APR_ARRAY_IDX(array, i, void *) =
> +            APR_ARRAY_IDX(array, swap_index, void *);
> +          APR_ARRAY_IDX(array, swap_index, void *) = tmp;
> +        }
> +    }
> +  else
>     {
> -      int swap_index = array->nelts - i - 1;
> -      void *tmp = APR_ARRAY_IDX(array, i, void *);
> +      size_t sz = array->elt_size;
> +      char *tmp = apr_palloc(scratch_pool, sz);
> +
> +      for (i = 0; i < array->nelts / 2; i++)
> +        {
> +          int swap_index = array->nelts - i - 1;
> +          char *x = array->elts + (sz * i);
> +          char *y = array->elts + (sz * swap_index);
>
> -      APR_ARRAY_IDX(array, i, void *) =
> -        APR_ARRAY_IDX(array, swap_index, void *);
> -      APR_ARRAY_IDX(array, swap_index, void *) = tmp;
> +          memcpy(tmp, x, sz);
> +          memcpy(x, y, sz);
> +          memcpy(y, tmp, sz);
> +        }
>     }
> }
>
Received on 2013-02-14 02:20:26 CET

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.