Author: dannas
Date: Thu Apr  8 16:16:54 2010
New Revision: 931989

URL: http://svn.apache.org/viewvc?rev=931989&view=rev
Log:
Use svn_path_component_count() instead of my own logic for code reuse.

* subversion/libsvn_client/patch.c
  (sort_compare_nr_of_path_elements): Move ..
  (sort_compare_path_component_count): .. to here. The name change
    reflects that we count path components instead of as previous, 
    individual characters. Replace my logic with 
    svn_path_component_count().
  (condense_deleted_targets): Update callers.

Suggested by: stsp

Modified:
    subversion/branches/svn-patch-improvements/subversion/libsvn_client/patch.c

Modified: 
subversion/branches/svn-patch-improvements/subversion/libsvn_client/patch.c
URL: 
http://svn.apache.org/viewvc/subversion/branches/svn-patch-improvements/subversion/libsvn_client/patch.c?rev=931989&r1=931988&r2=931989&view=diff
==============================================================================
--- subversion/branches/svn-patch-improvements/subversion/libsvn_client/patch.c 
(original)
+++ subversion/branches/svn-patch-improvements/subversion/libsvn_client/patch.c 
Thu Apr  8 16:16:54 2010
@@ -1351,22 +1351,13 @@ add_target_to_hash_keyed_by_parent_dir(a
  * subdir than B. That means that the path with the most subdirs is placed
  * first. */
 static int
-sort_compare_nr_of_path_elements(const svn_sort__item_t *a, 
-                                 const svn_sort__item_t *b)
+sort_compare_path_component_count(const svn_sort__item_t *a, 
+                                  const svn_sort__item_t *b)
 {
-  const char *astr, *bstr;
-  int n_a = 0, n_b = 0, i;
-  
-  astr = a->key;
-  bstr = b->key;
-
-  for (i = 0; i < a->klen; i++)
-    if (astr[i] == '/')
-      n_a++;
-
-  for (i = 0; i < b->klen; i++)
-    if (bstr[i] == '/')
-      n_b++;
+  apr_size_t n_a = 0, n_b = 0;
+
+  n_a = svn_path_component_count(a->key);
+  n_b = svn_path_component_count(b->key);
 
   if (n_a > n_b)
     return -1;
@@ -1409,7 +1400,7 @@ condense_deleted_targets(apr_array_heade
   /* ... Then we sort the keys to allow us to detect when multiple subdirs
    * should be deleted. */
   sorted_keys = svn_sort__hash(targets_to_be_deleted,
-                               sort_compare_nr_of_path_elements,
+                               sort_compare_path_component_count,
                                scratch_pool);
 
   /* For each directory that contains targets to be deleted determine if the
@@ -1459,7 +1450,7 @@ condense_deleted_targets(apr_array_heade
            * path, we're guarenteed that it will be inserted later. We do
            * the sort and just continue our iteration. */
           sorted_keys = svn_sort__hash(targets_to_be_deleted,
-                                       sort_compare_nr_of_path_elements,
+                                       sort_compare_path_component_count,
                                        scratch_pool);
         }
       else


Reply via email to