public
Last active

[gsoc-diff] reduce number of rec accesses

  • Download Gist
raw.foo.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
diff --git a/xdiff/xhistogram.c b/xdiff/xhistogram.c
index ea7b82d..d26c57c 100644
--- a/xdiff/xhistogram.c
+++ b/xdiff/xhistogram.c
@@ -52,7 +52,7 @@ struct region {
#define get_rec(env, s, l) \
(env->xdf##s.recs[l-1])
-static int cmp_recs(xpparam_t const *xpp, xdfenv_t *env,
+static int cmp_recs(xpparam_t const *xpp,
xrecord_t *r1, xrecord_t *r2)
{
return r1->ha == r2->ha &&
@@ -60,14 +60,17 @@ static int cmp_recs(xpparam_t const *xpp, xdfenv_t *env,
xpp->flags);
}
+#define cmp_xrecord_t(index, r1, s, l) \
+ (cmp_recs(index->xpp, r1, get_rec(index->env, s, l)))
+
#define cmp_env(xpp, env, s1, l1, s2, l2) \
- (cmp_recs(xpp, env, get_rec(env, s1, l1), get_rec(env, s2, l2)))
+ (cmp_recs(xpp, get_rec(env, s1, l1), get_rec(env, s2, l2)))
#define cmp(i, s1, l1, s2, l2) \
(cmp_env(i->xpp, i->env, s1, l1, s2, l2))
-#define table_hash(index, side, line) \
- XDL_HASHLONG((get_rec(index->env, side, line))->ha, index->table_bits)
+#define table_hash(index, rec) \
+ XDL_HASHLONG(rec->ha, index->table_bits)
static int scanA(struct histindex *index, int line1, int count1)
{
@@ -75,14 +78,16 @@ static int scanA(struct histindex *index, int line1, int count1)
unsigned int chain_len;
unsigned int new_cnt;
unsigned long rec;
+ xrecord_t *arec;
for (ptr = LINE_END(1); line1 <= ptr; ptr--) {
- tbl_idx = table_hash(index, 1, ptr);
+ arec = get_rec(index->env, 1, ptr);
+ tbl_idx = table_hash(index, arec);
chain_len = 0;
for (rec_idx = index->table[tbl_idx]; rec_idx != 0; ) {
rec = index->recs[rec_idx];
- if (cmp(index, 1, REC_PTR(rec), 1, ptr)) {
+ if (cmp_xrecord_t(index, arec, 1, REC_PTR(rec))) {
new_cnt = REC_CNT(rec) + 1;
if (new_cnt > MAX_CNT)
new_cnt = MAX_CNT;
@@ -123,7 +128,8 @@ static int try_lcs(struct histindex *index, struct region *lcs, int b_ptr,
int line1, int count1, int line2, int count2)
{
unsigned int b_next = b_ptr + 1;
- unsigned int rec_idx = index->table[table_hash(index, 2, b_ptr)];
+ xrecord_t *brec = get_rec(index->env, 2, b_ptr);
+ unsigned int rec_idx = index->table[table_hash(index, brec)];
unsigned long rec;
unsigned int as, ae, bs, be, np, rc;
int should_break;
@@ -138,7 +144,7 @@ static int try_lcs(struct histindex *index, struct region *lcs, int b_ptr,
}
as = REC_PTR(rec);
- if (!cmp(index, 1, as, 2, b_ptr))
+ if (!cmp_xrecord_t(index, brec, 1, as))
continue;
index->has_common = 1;

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.