Skip to content

Commit af82c78

Browse files
Kirill Smelkovgitster
authored andcommitted
combine-diff: combine_diff_path.len is not needed anymore
The field was used in order to speed-up name comparison and also to mark removed paths by setting it to 0. Because the updated code does significantly less strcmp and also just removes paths from the list and free right after we know a path will not be needed, it is not needed anymore. Signed-off-by: Kirill Smelkov <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8518ff8 commit af82c78

File tree

3 files changed

+9
-24
lines changed

3 files changed

+9
-24
lines changed

combine-diff.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,
3131
p->path = (char *) &(p->parent[num_parent]);
3232
memcpy(p->path, path, len);
3333
p->path[len] = 0;
34-
p->len = len;
3534
p->next = NULL;
3635
memset(p->parent, 0,
3736
sizeof(p->parent[0]) * num_parent);
@@ -1234,8 +1233,6 @@ void show_combined_diff(struct combine_diff_path *p,
12341233
{
12351234
struct diff_options *opt = &rev->diffopt;
12361235

1237-
if (!p->len)
1238-
return;
12391236
if (opt->output_format & (DIFF_FORMAT_RAW |
12401237
DIFF_FORMAT_NAME |
12411238
DIFF_FORMAT_NAME_STATUS))
@@ -1299,11 +1296,8 @@ static void handle_combined_callback(struct diff_options *opt,
12991296
q.queue = xcalloc(num_paths, sizeof(struct diff_filepair *));
13001297
q.alloc = num_paths;
13011298
q.nr = num_paths;
1302-
for (i = 0, p = paths; p; p = p->next) {
1303-
if (!p->len)
1304-
continue;
1299+
for (i = 0, p = paths; p; p = p->next)
13051300
q.queue[i++] = combined_pair(p, num_parent);
1306-
}
13071301
opt->format_callback(&q, opt, opt->format_callback_data);
13081302
for (i = 0; i < num_paths; i++)
13091303
free_combined_pair(q.queue[i]);
@@ -1369,11 +1363,9 @@ void diff_tree_combined(const unsigned char *sha1,
13691363
diff_flush(&diffopts);
13701364
}
13711365

1372-
/* find out surviving paths */
1373-
for (num_paths = 0, p = paths; p; p = p->next) {
1374-
if (p->len)
1375-
num_paths++;
1376-
}
1366+
/* find out number of surviving paths */
1367+
for (num_paths = 0, p = paths; p; p = p->next)
1368+
num_paths++;
13771369

13781370
/* order paths according to diffcore_order */
13791371
if (opt->orderfile && num_paths) {
@@ -1399,10 +1391,8 @@ void diff_tree_combined(const unsigned char *sha1,
13991391
if (opt->output_format & (DIFF_FORMAT_RAW |
14001392
DIFF_FORMAT_NAME |
14011393
DIFF_FORMAT_NAME_STATUS)) {
1402-
for (p = paths; p; p = p->next) {
1403-
if (p->len)
1404-
show_raw_diff(p, num_parent, rev);
1405-
}
1394+
for (p = paths; p; p = p->next)
1395+
show_raw_diff(p, num_parent, rev);
14061396
needsep = 1;
14071397
}
14081398
else if (opt->output_format &
@@ -1415,11 +1405,9 @@ void diff_tree_combined(const unsigned char *sha1,
14151405
if (needsep)
14161406
printf("%s%c", diff_line_prefix(opt),
14171407
opt->line_termination);
1418-
for (p = paths; p; p = p->next) {
1419-
if (p->len)
1420-
show_patch_diff(p, num_parent, dense,
1421-
0, rev);
1422-
}
1408+
for (p = paths; p; p = p->next)
1409+
show_patch_diff(p, num_parent, dense,
1410+
0, rev);
14231411
}
14241412
}
14251413

diff-lib.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
124124
dpath->path = (char *) &(dpath->parent[5]);
125125

126126
dpath->next = NULL;
127-
dpath->len = path_len;
128127
memcpy(dpath->path, ce->name, path_len);
129128
dpath->path[path_len] = '\0';
130129
hashclr(dpath->sha1);
@@ -326,7 +325,6 @@ static int show_modified(struct rev_info *revs,
326325
p = xmalloc(combine_diff_path_size(2, pathlen));
327326
p->path = (char *) &p->parent[2];
328327
p->next = NULL;
329-
p->len = pathlen;
330328
memcpy(p->path, new->name, pathlen);
331329
p->path[pathlen] = 0;
332330
p->mode = mode;

diff.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ extern int diff_root_tree_sha1(const unsigned char *new, const char *base,
198198

199199
struct combine_diff_path {
200200
struct combine_diff_path *next;
201-
int len;
202201
char *path;
203202
unsigned int mode;
204203
unsigned char sha1[20];

0 commit comments

Comments
 (0)