subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From julianf...@apache.org
Subject svn commit: r1445967 - in /subversion/trunk/subversion: include/svn_sorts.h libsvn_subr/mergeinfo.c libsvn_subr/sorts.c
Date Wed, 13 Feb 2013 22:54:37 GMT
Author: julianfoad
Date: Wed Feb 13 22:54:37 2013
New Revision: 1445967

URL: http://svn.apache.org/r1445967
Log:
Introduce svn_sort__array_reverse(), and use it in svn_rangelist_reverse()
which should now be more efficient because it was previously swapping the
pointed-to structures rather than just the pointers.

* subversion/include/svn_sorts.h,
  subversion/libsvn_subr/sorts.c
  (svn_sort__array_reverse): New function.

* subversion/libsvn_subr/mergeinfo.c
  (svn_rangelist_reverse): Use it.

Modified:
    subversion/trunk/subversion/include/svn_sorts.h
    subversion/trunk/subversion/libsvn_subr/mergeinfo.c
    subversion/trunk/subversion/libsvn_subr/sorts.c

Modified: subversion/trunk/subversion/include/svn_sorts.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_sorts.h?rev=1445967&r1=1445966&r2=1445967&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_sorts.h (original)
+++ subversion/trunk/subversion/include/svn_sorts.h Wed Feb 13 22:54:37 2013
@@ -208,6 +208,16 @@ svn_sort__array_delete(apr_array_header_
                        int delete_index,
                        int elements_to_delete);
 
+/* Reverse the order of elements in @a array, in place.  The elements of
+ * @a array shall be pointers.
+ *
+ * Non-pointer elements could be supported in future.  The @a scratch_pool
+ * is currently unused but could be used in future.
+ */
+void
+svn_sort__array_reverse(apr_array_header_t *array,
+                        apr_pool_t *scratch_pool);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */

Modified: subversion/trunk/subversion/libsvn_subr/mergeinfo.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/mergeinfo.c?rev=1445967&r1=1445966&r2=1445967&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/mergeinfo.c (original)
+++ subversion/trunk/subversion/libsvn_subr/mergeinfo.c Wed Feb 13 22:54:37 2013
@@ -1201,26 +1201,15 @@ range_swap_endpoints(svn_merge_range_t *
 svn_error_t *
 svn_rangelist_reverse(svn_rangelist_t *rangelist, apr_pool_t *pool)
 {
-  int i, swap_index;
-  svn_merge_range_t range;
-  for (i = 0; i < rangelist->nelts / 2; i++)
-    {
-      swap_index = rangelist->nelts - i - 1;
-      range = *APR_ARRAY_IDX(rangelist, i, svn_merge_range_t *);
-      *APR_ARRAY_IDX(rangelist, i, svn_merge_range_t *) =
-        *APR_ARRAY_IDX(rangelist, swap_index, svn_merge_range_t *);
-      *APR_ARRAY_IDX(rangelist, swap_index, svn_merge_range_t *) = range;
-      range_swap_endpoints(APR_ARRAY_IDX(rangelist, swap_index,
-                                         svn_merge_range_t *));
+  int i;
+
+  svn_sort__array_reverse(rangelist, pool);
+
+  for (i = 0; i < rangelist->nelts; i++)
+    {
       range_swap_endpoints(APR_ARRAY_IDX(rangelist, i, svn_merge_range_t *));
     }
 
-  /* If there's an odd number of elements, we still need to swap the
-     end points of the remaining range. */
-  if (rangelist->nelts % 2 == 1)
-    range_swap_endpoints(APR_ARRAY_IDX(rangelist, rangelist->nelts / 2,
-                                       svn_merge_range_t *));
-
   return SVN_NO_ERROR;
 }
 

Modified: subversion/trunk/subversion/libsvn_subr/sorts.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/sorts.c?rev=1445967&r1=1445966&r2=1445967&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/sorts.c (original)
+++ subversion/trunk/subversion/libsvn_subr/sorts.c Wed Feb 13 22:54:37 2013
@@ -270,3 +270,22 @@ svn_sort__array_delete(apr_array_header_
       arr->nelts -= elements_to_delete;
     }
 }
+
+void
+svn_sort__array_reverse(apr_array_header_t *array,
+                        apr_pool_t *scratch_pool)
+{
+  int i;
+
+  assert(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 *);
+
+      APR_ARRAY_IDX(array, i, void *) =
+        APR_ARRAY_IDX(array, swap_index, void *);
+      APR_ARRAY_IDX(array, swap_index, void *) = tmp;
+    }
+}



Mime
View raw message