rerere: stop looping unnecessarily
handle_cache() loops 3 times starting from an index entry that is unmerged, while ignoring an entry for a path that is different from what we are looking for. As the index is sorted, once we see a different path, we know we saw all stages for the path we are interested in. Just loop while we see the same path and then break, instead of continuing for 3 times. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jun 30, 2015 at 16:10 UTC
74444d4ec4c23d254040de7b2637660b7f141110
1 file changed
+7
-10
rerere.c
+7
-10
@@ -329,24 +329,21 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
329
return -1;
330
pos = -pos - 1;
331
332
- for (i = 0; i < 3; i++) {
332
+ while (pos < active_nr) {
333
enum object_type type;
334
unsigned long size;
335
- int j;
335
337
- if (active_nr <= pos)
338
- break;
336
ce = active_cache[pos++];
337
if (ce_namelen(ce) != len || memcmp(ce->name, path, len))
341
- continue;
342
- j = ce_stage(ce) - 1;
343
- mmfile[j].ptr = read_sha1_file(ce->sha1, &type, &size);
344
- mmfile[j].size = size;
338
+ break;
339
+ i = ce_stage(ce) - 1;
340
+ mmfile[i].ptr = read_sha1_file(ce->sha1, &type, &size);
341
+ mmfile[i].size = size;
342
}
346
- for (i = 0; i < 3; i++) {
343
+ for (i = 0; i < 3; i++)
344
if (!mmfile[i].ptr && !mmfile[i].size)
345
mmfile[i].ptr = xstrdup("");
349
- }
346
+
347
/*
348
* NEEDSWORK: handle conflicts from merges with
349
* merge.renormalize set, too