[PATCH 3/4] Introduce "abstract class" to make _locate_element() more independant of diff_rename_dst.
The dst_obj struct acts as an absract base class for the elements which
_locate_element() manipulates arrays of.
---
diffcore-rename.c | 21 +++++++++++++--------
1 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 6e7ab4a..a674fbb 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -6,12 +6,16 @@
#include "diffcore.h"
#include "hash.h"
+
+/* "Abstract class" for lists of filespecs */
+struct dst_obj {
+ struct diff_filespec *two;
+};
#define locate_element(list,elem,insert_ok) \
_locate_element(elem, &list##_nr, &list##_alloc, \
sizeof(*list), insert_ok)
-/* Table of rename/copy destinations */
-
+/* Table of rename/copy destinations, "subclass" of dst_obj */
static struct diff_rename_dst {
struct diff_filespec *two;
struct diff_filepair *pair;
@@ -20,18 +24,18 @@ static int rename_dst_nr, rename_dst_alloc;
#define locate_rename_dst(elem,insert_ok) \
locate_element(rename_dst, elem, insert_ok)
-static struct diff_rename_dst *_locate_element(struct diff_filespec *two,
- int *elem_nr_p, int *elem_alloc_p,
- size_t elem_size, int insert_ok)
+static void *_locate_element(struct diff_filespec *two,
+ int *elem_nr_p, int *elem_alloc_p,
+ size_t elem_size, int insert_ok)
{
int first, last;
- struct diff_rename_dst *first_elem_p;
+ struct dst_obj *first_elem_p;
first = 0;
last = (*elem_nr_p);
while (last > first) {
int next = (last + first) >> 1;
- struct diff_rename_dst *dst = (void*)rename_dst + (next * elem_size);
+ struct dst_obj *dst = (void*)rename_dst + (next * elem_size);
int cmp = strcmp(two->path, dst->two->path);
if (!cmp)
return dst;
@@ -58,7 +62,8 @@ static struct diff_rename_dst *_locate_element(struct diff_filespec *two,
((*elem_nr_p) - first - 1) * elem_size);
first_elem_p->two = alloc_filespec(two->path);
fill_filespec(first_elem_p->two, two->sha1, two->mode);
- first_elem_p->pair = NULL;
+ memset(((struct dst_obj *)first_elem_p) + 1, 0,
+ elem_size - sizeof(struct dst_obj));
return first_elem_p;
}
--
1.7.2.3