Now offset calculations don't rely on pointer arithmetic any more, paving the way for complete decoupling from diff_rename_dst. --- diffcore-rename.c | 23 +++++++++++++---------- 1 files changed, 13 insertions(+), 10 deletions(-) diff --git a/diffcore-rename.c b/diffcore-rename.c index fc554e4..6e7ab4a 100644 --- a/diffcore-rename.c +++ b/diffcore-rename.c @@ -8,7 +8,7 @@ #define locate_element(list,elem,insert_ok) \ _locate_element(elem, &list##_nr, &list##_alloc, \ - insert_ok) + sizeof(*list), insert_ok) /* Table of rename/copy destinations */ @@ -22,15 +22,16 @@ static int rename_dst_nr, rename_dst_alloc; static struct diff_rename_dst *_locate_element(struct diff_filespec *two, int *elem_nr_p, int *elem_alloc_p, - int insert_ok) + size_t elem_size, int insert_ok) { int first, last; + struct diff_rename_dst *first_elem_p; first = 0; last = (*elem_nr_p); while (last > first) { int next = (last + first) >> 1; - struct diff_rename_dst *dst = &(rename_dst[next]); + struct diff_rename_dst *dst = (void*)rename_dst + (next * elem_size); int cmp = strcmp(two->path, dst->two->path); if (!cmp) return dst; @@ -47,16 +48,18 @@ static struct diff_rename_dst *_locate_element(struct diff_filespec *two, if ((*elem_alloc_p) <= (*elem_nr_p)) { (*elem_alloc_p) = alloc_nr(*elem_alloc_p); rename_dst = xrealloc(rename_dst, - (*elem_alloc_p) * sizeof(*rename_dst)); + (*elem_alloc_p) * elem_size); } (*elem_nr_p)++; + first_elem_p = (void*)rename_dst + first * elem_size; if (first < (*elem_nr_p)) - memmove(rename_dst + first + 1, rename_dst + first, - ((*elem_nr_p) - first - 1) * sizeof(*rename_dst)); - rename_dst[first].two = alloc_filespec(two->path); - fill_filespec(rename_dst[first].two, two->sha1, two->mode); - rename_dst[first].pair = NULL; - return &(rename_dst[first]); + memmove((void*)rename_dst + (first + 1) * elem_size, + first_elem_p, + ((*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; + return first_elem_p; } /* Table of rename/copy src files */ -- 1.7.2.3 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html