Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rctay
Created July 7, 2011 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rctay/1069099 to your computer and use it in GitHub Desktop.
Save rctay/1069099 to your computer and use it in GitHub Desktop.
[gsoc-diff] reduce number of rec accesses
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment