Skip to content

Commit 74444d4

Browse files
committed
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 <[email protected]>
1 parent 67711cd commit 74444d4

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

rerere.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -329,24 +329,21 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
329329
return -1;
330330
pos = -pos - 1;
331331

332-
for (i = 0; i < 3; i++) {
332+
while (pos < active_nr) {
333333
enum object_type type;
334334
unsigned long size;
335-
int j;
336335

337-
if (active_nr <= pos)
338-
break;
339336
ce = active_cache[pos++];
340337
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;
345342
}
346-
for (i = 0; i < 3; i++) {
343+
for (i = 0; i < 3; i++)
347344
if (!mmfile[i].ptr && !mmfile[i].size)
348345
mmfile[i].ptr = xstrdup("");
349-
}
346+
350347
/*
351348
* NEEDSWORK: handle conflicts from merges with
352349
* merge.renormalize set, too

0 commit comments

Comments
 (0)