subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pbu...@apache.org
Subject svn commit: r1187042 - /subversion/trunk/subversion/libsvn_subr/sorts.c
Date Thu, 20 Oct 2011 20:44:26 GMT
Author: pburba
Date: Thu Oct 20 20:44:26 2011
New Revision: 1187042

URL: http://svn.apache.org/viewvc?rev=1187042&view=rev
Log:
* subversion/libsvn_subr/sorts.c
  (svn_sort__array_delete): Simplify the code a bit.  See
   http://svn.haxx.se/dev/archive-2011-10/0306.shtml

Modified:
    subversion/trunk/subversion/libsvn_subr/sorts.c

Modified: subversion/trunk/subversion/libsvn_subr/sorts.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/sorts.c?rev=1187042&r1=1187041&r2=1187042&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/sorts.c (original)
+++ subversion/trunk/subversion/libsvn_subr/sorts.c Thu Oct 20 20:44:26 2011
@@ -257,23 +257,16 @@ svn_sort__array_delete(apr_array_header_
       && elements_to_delete > 0
       && (elements_to_delete + 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 if ((delete_index + elements_to_delete) == arr->nelts)
-        {
-          /* Delete the last ELEMENTS_TO_DELETE elements. */
-          arr->nelts -= elements_to_delete;
-        }
-      else
-        {
-          memmove(
-            arr->elts + arr->elt_size * delete_index,
-            arr->elts + (arr->elt_size * (delete_index + elements_to_delete)),
-            arr->elt_size * (arr->nelts - elements_to_delete - delete_index));
-          arr->nelts -= elements_to_delete;
-        }
+      /* If we are not deleting a block of elements that extends to the end
+         of the array, then we need to move the remaining elements to keep
+         the array contiguous. */
+      if ((elements_to_delete + delete_index) < arr->nelts)
+        memmove(
+          arr->elts + arr->elt_size * delete_index,
+          arr->elts + (arr->elt_size * (delete_index + elements_to_delete)),
+          arr->elt_size * (arr->nelts - elements_to_delete - delete_index));
+
+      /* Delete the last ELEMENTS_TO_DELETE elements. */
+      arr->nelts -= elements_to_delete;
     }
 }



Mime
View raw message