Skip to content

Commit 204aa2d

Browse files
phillipwoodgitster
authored andcommitted
patience diff: remove unnecessary string comparisons
xdl_prepare_env() calls xdl_classify_record() which arranges for the hashes of non-matching lines to be different so lines can be tested for equality by comparing just their hashes. This reduces the time taken to calculate the diff of v2.28.0 to v2.29.0 by ~3-4%. Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e4f4299 commit 204aa2d

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

xdiff/xpatience.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ static void insert_record(xpparam_t const *xpp, int line, struct hashmap *map,
9090
{
9191
xrecord_t **records = pass == 1 ?
9292
map->env->xdf1.recs : map->env->xdf2.recs;
93-
xrecord_t *record = records[line - 1], *other;
93+
xrecord_t *record = records[line - 1];
9494
/*
9595
* After xdl_prepare_env() (or more precisely, due to
9696
* xdl_classify_record()), the "ha" member of the records (AKA lines)
@@ -104,11 +104,7 @@ static void insert_record(xpparam_t const *xpp, int line, struct hashmap *map,
104104
int index = (int)((record->ha << 1) % map->alloc);
105105

106106
while (map->entries[index].line1) {
107-
other = map->env->xdf1.recs[map->entries[index].line1 - 1];
108-
if (map->entries[index].hash != record->ha ||
109-
!xdl_recmatch(record->ptr, record->size,
110-
other->ptr, other->size,
111-
map->xpp->flags)) {
107+
if (map->entries[index].hash != record->ha) {
112108
if (++index >= map->alloc)
113109
index = 0;
114110
continue;
@@ -253,8 +249,7 @@ static int match(struct hashmap *map, int line1, int line2)
253249
{
254250
xrecord_t *record1 = map->env->xdf1.recs[line1 - 1];
255251
xrecord_t *record2 = map->env->xdf2.recs[line2 - 1];
256-
return xdl_recmatch(record1->ptr, record1->size,
257-
record2->ptr, record2->size, map->xpp->flags);
252+
return record1->ha == record2->ha;
258253
}
259254

260255
static int patience_diff(mmfile_t *file1, mmfile_t *file2,

0 commit comments

Comments
 (0)