rerere: remove dubious "tail_optimization"
It is dubious if it is cheaper to shift entries repeatedly using memmove() to collect entries that needs to be written out in front of an array than simply marking the entries to be skipped. In addition, the label called this "tail optimization", but this obviously is not what people usually call with that name. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jun 22, 2008 at 00:27 UTC
51e0d0a67b8d31e92d52e15b577afb079359ec63
1 file changed
+9
-10
builtin-rerere.c
+9
-10
@@ -66,8 +66,12 @@ static int write_rr(struct path_list *rr, int out_fd)
66
{
67
int i;
68
for (i = 0; i < rr->nr; i++) {
69
- const char *path = rr->items[i].path;
70
- int length = strlen(path) + 1;
69
+ const char *path;
70
+ int length;
71
+ if (!rr->items[i].util)
72
+ continue;
73
+ path = rr->items[i].path;
74
+ length = strlen(path) + 1;
75
if (write_in_full(out_fd, rr->items[i].util, 40) != 40 ||
76
write_in_full(out_fd, "\t", 1) != 1 ||
77
write_in_full(out_fd, path, length) != length)
@@ -319,7 +323,7 @@ static int do_plain_rerere(struct path_list *rr, int fd)
323
if (!merge(name, path)) {
324
fprintf(stderr, "Resolved '%s' using "
325
"previous resolution.\n", path);
322
- goto tail_optimization;
326
+ goto mark_resolved;
327
}
328
}
329
@@ -330,13 +334,8 @@ static int do_plain_rerere(struct path_list *rr, int fd)
334
335
fprintf(stderr, "Recorded resolution for '%s'.\n", path);
336
copy_file(rr_path(name, "postimage"), path, 0666);
333
-tail_optimization:
334
- if (i < rr->nr - 1)
335
- memmove(rr->items + i,
336
- rr->items + i + 1,
337
- sizeof(rr->items[0]) * (rr->nr - i - 1));
338
- rr->nr--;
339
- i--;
337
+ mark_resolved:
338
+ rr->items[i].util = NULL;
339
}
340
341
return write_rr(rr, fd);