diff options
Diffstat (limited to 'xdiff')
-rw-r--r-- | xdiff/xdiff.h | 3 | ||||
-rw-r--r-- | xdiff/xdiffi.c | 33 | ||||
-rw-r--r-- | xdiff/xutils.c | 106 |
3 files changed, 1 insertions, 141 deletions
diff --git a/xdiff/xdiff.h b/xdiff/xdiff.h index 8db16d4ae6..b090ad8eac 100644 --- a/xdiff/xdiff.h +++ b/xdiff/xdiff.h @@ -41,8 +41,7 @@ extern "C" { #define XDF_IGNORE_BLANK_LINES (1 << 7) -#define XDF_COMPACTION_HEURISTIC (1 << 8) -#define XDF_INDENT_HEURISTIC (1 << 9) +#define XDF_INDENT_HEURISTIC (1 << 8) #define XDL_EMIT_FUNCNAMES (1 << 0) #define XDL_EMIT_FUNCCONTEXT (1 << 2) diff --git a/xdiff/xdiffi.c b/xdiff/xdiffi.c index 760fbb6db7..93a65680a1 100644 --- a/xdiff/xdiffi.c +++ b/xdiff/xdiffi.c @@ -400,11 +400,6 @@ static xdchange_t *xdl_add_change(xdchange_t *xscr, long i1, long i2, long chg1, } -static int is_blank_line(xrecord_t *rec, long flags) -{ - return xdl_blankline(rec->ptr, rec->size, flags); -} - static int recs_match(xrecord_t *rec1, xrecord_t *rec2, long flags) { return (rec1->ha == rec2->ha && @@ -821,7 +816,6 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { struct xdlgroup g, go; long earliest_end, end_matching_other; long groupsize; - unsigned int blank_lines; group_init(xdf, &g); group_init(xdfo, &go); @@ -846,13 +840,6 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { */ end_matching_other = -1; - /* - * Boolean value that records whether there are any blank - * lines that could be made to be the last line of this - * group. - */ - blank_lines = 0; - /* Shift the group backward as much as possible: */ while (!group_slide_up(xdf, &g, flags)) if (group_previous(xdfo, &go)) @@ -869,11 +856,6 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { /* Now shift the group forward as far as possible: */ while (1) { - if (!blank_lines) - blank_lines = is_blank_line( - xdf->recs[g.end - 1], - flags); - if (group_slide_down(xdf, &g, flags)) break; if (group_next(xdfo, &go)) @@ -906,21 +888,6 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) { if (group_previous(xdfo, &go)) xdl_bug("group sync broken sliding to match"); } - } else if ((flags & XDF_COMPACTION_HEURISTIC) && blank_lines) { - /* - * Compaction heuristic: if it is possible to shift the - * group to make its bottom line a blank line, do so. - * - * As we already shifted the group forward as far as - * possible in the earlier loop, we only need to handle - * backward shifts, not forward ones. - */ - while (!is_blank_line(xdf->recs[g.end - 1], flags)) { - if (group_slide_up(xdf, &g, flags)) - xdl_bug("blank line disappeared"); - if (group_previous(xdfo, &go)) - xdl_bug("group sync broken sliding to blank line"); - } } else if (flags & XDF_INDENT_HEURISTIC) { /* * Indent heuristic: a group of pure add/delete lines diff --git a/xdiff/xutils.c b/xdiff/xutils.c index 027192a1c7..04d7b32e4e 100644 --- a/xdiff/xutils.c +++ b/xdiff/xutils.c @@ -264,110 +264,6 @@ static unsigned long xdl_hash_record_with_whitespace(char const **data, return ha; } -#ifdef XDL_FAST_HASH - -#define REPEAT_BYTE(x) ((~0ul / 0xff) * (x)) - -#define ONEBYTES REPEAT_BYTE(0x01) -#define NEWLINEBYTES REPEAT_BYTE(0x0a) -#define HIGHBITS REPEAT_BYTE(0x80) - -/* Return the high bit set in the first byte that is a zero */ -static inline unsigned long has_zero(unsigned long a) -{ - return ((a - ONEBYTES) & ~a) & HIGHBITS; -} - -static inline long count_masked_bytes(unsigned long mask) -{ - if (sizeof(long) == 8) { - /* - * Jan Achrenius on G+: microoptimized version of - * the simpler "(mask & ONEBYTES) * ONEBYTES >> 56" - * that works for the bytemasks without having to - * mask them first. - */ - /* - * return mask * 0x0001020304050608 >> 56; - * - * Doing it like this avoids warnings on 32-bit machines. - */ - long a = (REPEAT_BYTE(0x01) / 0xff + 1); - return mask * a >> (sizeof(long) * 7); - } else { - /* Carl Chatfield / Jan Achrenius G+ version for 32-bit */ - /* (000000 0000ff 00ffff ffffff) -> ( 1 1 2 3 ) */ - long a = (0x0ff0001 + mask) >> 23; - /* Fix the 1 for 00 case */ - return a & mask; - } -} - -unsigned long xdl_hash_record(char const **data, char const *top, long flags) -{ - unsigned long hash = 5381; - unsigned long a = 0, mask = 0; - char const *ptr = *data; - char const *end = top - sizeof(unsigned long) + 1; - - if (flags & XDF_WHITESPACE_FLAGS) - return xdl_hash_record_with_whitespace(data, top, flags); - - ptr -= sizeof(unsigned long); - do { - hash += hash << 5; - hash ^= a; - ptr += sizeof(unsigned long); - if (ptr >= end) - break; - a = *(unsigned long *)ptr; - /* Do we have any '\n' bytes in this word? */ - mask = has_zero(a ^ NEWLINEBYTES); - } while (!mask); - - if (ptr >= end) { - /* - * There is only a partial word left at the end of the - * buffer. Because we may work with a memory mapping, - * we have to grab the rest byte by byte instead of - * blindly reading it. - * - * To avoid problems with masking in a signed value, - * we use an unsigned char here. - */ - const char *p; - for (p = top - 1; p >= ptr; p--) - a = (a << 8) + *((const unsigned char *)p); - mask = has_zero(a ^ NEWLINEBYTES); - if (!mask) - /* - * No '\n' found in the partial word. Make a - * mask that matches what we read. - */ - mask = 1UL << (8 * (top - ptr) + 7); - } - - /* The mask *below* the first high bit set */ - mask = (mask - 1) & ~mask; - mask >>= 7; - hash += hash << 5; - hash ^= a & mask; - - /* Advance past the last (possibly partial) word */ - ptr += count_masked_bytes(mask); - - if (ptr < top) { - assert(*ptr == '\n'); - ptr++; - } - - *data = ptr; - - return hash; -} - -#else /* XDL_FAST_HASH */ - unsigned long xdl_hash_record(char const **data, char const *top, long flags) { unsigned long ha = 5381; char const *ptr = *data; @@ -384,8 +280,6 @@ unsigned long xdl_hash_record(char const **data, char const *top, long flags) { return ha; } -#endif /* XDL_FAST_HASH */ - unsigned int xdl_hashbits(unsigned int size) { unsigned int val = 1, bits = 0; |