Skip to content

Commit c27afcb

Browse files
phillipwoodgitster
authored andcommitted
xdiff: remove "line_hash" field from xrecord_t
Prior to commit 6a26019 (xdiff: split xrecord_t.ha into line_hash and minimal_perfect_hash, 2025-11-18) the "ha" field of xrecord_t initially held the "line_hash" value and once the line had been interned that field was updated to hold the "minimal_perfect_hash". The "line_hash" is only used to intern the line so there is no point in storing it after all the input lines have been interned. Removing the "line_hash" field from xrecord_t and storing it in xdlclass_t where it is actually used makes it clearer that it is a temporary value and it should not be used once we're calculated the "minimal_perfect_hash". This also reduces the size of xrecord_t by 25% on 64-bit platforms and 40% on 32-bit platforms. While the struct is small we create one instance per input line so any saving is welcome. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 22ce0cb commit c27afcb

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

xdiff/xprepare.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#define INVESTIGATE 2
3535

3636
typedef struct s_xdlclass {
37+
uint64_t line_hash;
3738
struct s_xdlclass *next;
3839
xrecord_t rec;
3940
long idx;
@@ -92,13 +93,14 @@ static void xdl_free_classifier(xdlclassifier_t *cf) {
9293
}
9394

9495

95-
static int xdl_classify_record(unsigned int pass, xdlclassifier_t *cf, xrecord_t *rec) {
96+
static int xdl_classify_record(unsigned int pass, xdlclassifier_t *cf, xrecord_t *rec,
97+
uint64_t line_hash) {
9698
size_t hi;
9799
xdlclass_t *rcrec;
98100

99-
hi = XDL_HASHLONG(rec->line_hash, cf->hbits);
101+
hi = XDL_HASHLONG(line_hash, cf->hbits);
100102
for (rcrec = cf->rchash[hi]; rcrec; rcrec = rcrec->next)
101-
if (rcrec->rec.line_hash == rec->line_hash &&
103+
if (rcrec->line_hash == line_hash &&
102104
xdl_recmatch((const char *)rcrec->rec.ptr, (long)rcrec->rec.size,
103105
(const char *)rec->ptr, (long)rec->size, cf->flags))
104106
break;
@@ -112,6 +114,7 @@ static int xdl_classify_record(unsigned int pass, xdlclassifier_t *cf, xrecord_t
112114
if (XDL_ALLOC_GROW(cf->rcrecs, cf->count, cf->alloc))
113115
return -1;
114116
cf->rcrecs[rcrec->idx] = rcrec;
117+
rcrec->line_hash = line_hash;
115118
rcrec->rec = *rec;
116119
rcrec->len1 = rcrec->len2 = 0;
117120
rcrec->next = cf->rchash[hi];
@@ -158,8 +161,7 @@ static int xdl_prepare_ctx(unsigned int pass, mmfile_t *mf, long narec, xpparam_
158161
crec = &xdf->recs[xdf->nrec++];
159162
crec->ptr = prev;
160163
crec->size = cur - prev;
161-
crec->line_hash = hav;
162-
if (xdl_classify_record(pass, cf, crec) < 0)
164+
if (xdl_classify_record(pass, cf, crec, hav) < 0)
163165
goto abort;
164166
}
165167
}

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)