Merge branch 'jh/string-list-micro-optim'
authorJunio C Hamano <gitster@pobox.com>
Mon, 24 Apr 2017 05:07:47 +0000 (22:07 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 24 Apr 2017 05:07:47 +0000 (22:07 -0700)
The string-list API used a custom reallocation strategy that was
very inefficient, instead of using the usual ALLOC_GROW() macro,
which has been fixed.

* jh/string-list-micro-optim:
string-list: use ALLOC_GROW macro when reallocing string_list

1  2 
string-list.c
diff --combined string-list.c
index 45016ad86dd5eb55534524cb50e30542e87fab70,1e27d9cec3208ff98e3b719077d496419e4136ec..003ca1879ef560b3db0ad9e1af8022c38800b500
@@@ -41,10 -41,7 +41,7 @@@ static int add_entry(int insert_at, str
        if (exact_match)
                return -1 - index;
  
-       if (list->nr + 1 >= list->alloc) {
-               list->alloc += 32;
-               REALLOC_ARRAY(list->items, list->alloc);
-       }
+       ALLOC_GROW(list->items, list->nr+1, list->alloc);
        if (index < list->nr)
                memmove(list->items + index + 1, list->items + index,
                                (list->nr - index)
@@@ -211,18 -208,21 +208,18 @@@ struct string_list_item *string_list_ap
                        list->strdup_strings ? xstrdup(string) : (char *)string);
  }
  
 -/* Yuck */
 -static compare_strings_fn compare_for_qsort;
 -
 -/* Only call this from inside string_list_sort! */
 -static int cmp_items(const void *a, const void *b)
 +static int cmp_items(const void *a, const void *b, void *ctx)
  {
 +      compare_strings_fn cmp = ctx;
        const struct string_list_item *one = a;
        const struct string_list_item *two = b;
 -      return compare_for_qsort(one->string, two->string);
 +      return cmp(one->string, two->string);
  }
  
  void string_list_sort(struct string_list *list)
  {
 -      compare_for_qsort = list->cmp ? list->cmp : strcmp;
 -      QSORT(list->items, list->nr, cmp_items);
 +      QSORT_S(list->items, list->nr, cmp_items,
 +              list->cmp ? list->cmp : strcmp);
  }
  
  struct string_list_item *unsorted_string_list_lookup(struct string_list *list,