Skip to content

Commit 5465d36

Browse files
committed
Merge branch 'pw/xdiff-cleanups'
Small clean-up of xdiff library to remove unnecessary data duplication. * pw/xdiff-cleanups: xdiff: remove unused data from xdlclass_t xdiff: remove "line_hash" field from xrecord_t
2 parents 73fd778 + 5086213 commit 5465d36

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

xdiff/xprepare.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
#define INVESTIGATE 2
3535

3636
typedef struct s_xdlclass {
37+
uint64_t line_hash;
3738
struct s_xdlclass *next;
38-
xrecord_t rec;
39+
const uint8_t *ptr;
40+
size_t size;
3941
long idx;
4042
long len1, len2;
4143
} xdlclass_t;
@@ -92,14 +94,15 @@ static void xdl_free_classifier(xdlclassifier_t *cf) {
9294
}
9395

9496

95-
static int xdl_classify_record(unsigned int pass, xdlclassifier_t *cf, xrecord_t *rec) {
97+
static int xdl_classify_record(unsigned int pass, xdlclassifier_t *cf, xrecord_t *rec,
98+
uint64_t line_hash) {
9699
size_t hi;
97100
xdlclass_t *rcrec;
98101

99-
hi = XDL_HASHLONG(rec->line_hash, cf->hbits);
102+
hi = XDL_HASHLONG(line_hash, cf->hbits);
100103
for (rcrec = cf->rchash[hi]; rcrec; rcrec = rcrec->next)
101-
if (rcrec->rec.line_hash == rec->line_hash &&
102-
xdl_recmatch((const char *)rcrec->rec.ptr, (long)rcrec->rec.size,
104+
if (rcrec->line_hash == line_hash &&
105+
xdl_recmatch((const char *)rcrec->ptr, (long)rcrec->size,
103106
(const char *)rec->ptr, (long)rec->size, cf->flags))
104107
break;
105108

@@ -112,7 +115,9 @@ static int xdl_classify_record(unsigned int pass, xdlclassifier_t *cf, xrecord_t
112115
if (XDL_ALLOC_GROW(cf->rcrecs, cf->count, cf->alloc))
113116
return -1;
114117
cf->rcrecs[rcrec->idx] = rcrec;
115-
rcrec->rec = *rec;
118+
rcrec->line_hash = line_hash;
119+
rcrec->ptr = rec->ptr;
120+
rcrec->size = rec->size;
116121
rcrec->len1 = rcrec->len2 = 0;
117122
rcrec->next = cf->rchash[hi];
118123
cf->rchash[hi] = rcrec;
@@ -158,8 +163,7 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
158163
crec = &xdf->recs[xdf->nrec++];
159164
crec->ptr = prev;
160165
crec->size = cur - prev;
161-
crec->line_hash = hav;
162-
if (xdl_classify_record(pass, cf, crec) < 0)
166+
if (xdl_classify_record(pass, cf, crec, hav) < 0)
163167
goto abort;
164168
}
165169
}

xdiff/xtypes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ typedef struct s_chastore {
4141
typedef struct s_xrecord {
4242
uint8_t const *ptr;
4343
size_t size;
44-
uint64_t line_hash;
4544
size_t minimal_perfect_hash;
4645
} xrecord_t;
4746

0 commit comments

Comments
 (0)