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 <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Phillip Wood committed
May 4, 2021 at 09:25 UTC
204aa2d24d83f308ef1ab128b1a7722daf9cfd56
1 file changed
+3
-8
xdiff/xpatience.c
+3
-8
@@ -90,7 +90,7 @@ static void insert_record(xpparam_t const *xpp, int line, struct hashmap *map,
90
{
91
xrecord_t **records = pass == 1 ?
92
map->env->xdf1.recs : map->env->xdf2.recs;
93
- xrecord_t *record = records[line - 1], *other;
93
+ xrecord_t *record = records[line - 1];
94
/*
95
* After xdl_prepare_env() (or more precisely, due to
96
* 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,
104
int index = (int)((record->ha << 1) % map->alloc);
105
106
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) {
108
if (++index >= map->alloc)
109
index = 0;
110
continue;
@@ -253,8 +249,7 @@ static int match(struct hashmap *map, int line1, int line2)
249
{
250
xrecord_t *record1 = map->env->xdf1.recs[line1 - 1];
251
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;
253
}
254
255
static int patience_diff(mmfile_t *file1, mmfile_t *file2,