diff --git a/diffcore-rename.c b/diffcore-rename.c
index 1626bdc..a146adf 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -24,8 +24,9 @@ static void rename_dst_init(struct diff_rename_dst *elem, struct diff_filespec *
fill_filespec(elem->two, ref_spec->sha1, ref_spec->mode);
elem->pair = NULL;
}
-declare_sorted_array(static, struct diff_rename_dst, rename_dst,
- rename_dst_cmp, rename_dst_init)
+declare_sorted_array_type(static, struct diff_rename_dst, rename_dst,
+ rename_dst_cmp, rename_dst_init);
+declare_sorted_array(static, struct diff_rename_dst, rename_dst, rename_dst);
/* Table of rename/copy src files */
static struct diff_rename_src {diff --git a/sorted-array.h b/sorted-array.h
index 03d5d1e..54fad20 100644
--- a/sorted-array.h
+++ b/sorted-array.h
@@ -1,15 +1,15 @@
-#define declare_sorted_array(MAYBESTATIC,ELEMTYPE,LIST,CMP,INIT) \
-MAYBESTATIC ELEMTYPE *LIST; \
-MAYBESTATIC int LIST##_nr, LIST##_alloc; \
-MAYBESTATIC ELEMTYPE *locate_##LIST(void *data, int insert_ok) \
+#define declare_sorted_array_type(MAYBESTATIC,ELEMTYPE,TYPENICK,CMP,INIT) \
+MAYBESTATIC ELEMTYPE *locate_type_##TYPENICK( \
+ ELEMTYPE **list_p, int *list_nr_p, int *list_nr_alloc, \
+ void *data, int insert_ok) \
{ \
int first, last; \
\
first = 0; \
- last = LIST##_nr; \
+ last = *list_nr_p; \
while (last > first) { \
int next = (last + first) >> 1; \
- ELEMTYPE *nextelem = &(LIST[next]); \
+ ELEMTYPE *nextelem = &((*list_p)[next]); \
int cmp = CMP(data, nextelem); \
if (!cmp) \
return nextelem; \@@ -23,14 +23,23 @@ MAYBESTATIC ELEMTYPE *locate_##LIST(void *data, int insert_ok) \
if (!insert_ok) \
return NULL; \
/* insert to make it at "first" */ \
- if (LIST##_alloc <= LIST##_nr) { \
- LIST##_alloc = alloc_nr(LIST##_alloc); \
- LIST = xrealloc(LIST, LIST##_alloc * sizeof(*LIST)); \
+ if (*list_nr_alloc <= *list_nr_p) { \
+ (*list_nr_alloc) = alloc_nr((*list_nr_alloc)); \
+ *list_p = xrealloc(*list_p, (*list_nr_alloc) * sizeof(**list_p)); \
} \
- LIST##_nr++; \
- if (first < LIST##_nr) \
- memmove(LIST + first + 1, LIST + first, \
- (LIST##_nr - first - 1) * sizeof(*LIST)); \
- INIT(&LIST[first], data); \
- return &(LIST[first]); \
+ (*list_nr_p)++; \
+ if (first < *list_nr_p) \
+ memmove(*list_p + first + 1, *list_p + first, \
+ (*list_nr_p - first - 1) * sizeof(**list_p)); \
+ INIT(&(*list_p)[first], data); \
+ return &((*list_p)[first]); \
+}
+
+#define declare_sorted_array(MAYBESTATIC,ELEMTYPE,TYPENICK,LIST) \
+MAYBESTATIC ELEMTYPE *LIST; \
+MAYBESTATIC int LIST##_nr, LIST##_alloc; \
+MAYBESTATIC ELEMTYPE *locate_##LIST(void *data, int insert_ok) \
+{ \
+ return locate_type_##TYPENICK(&LIST, &LIST##_nr, &LIST##_alloc, \
+ data, insert_ok); \
}--
1.7.2.3