xdiff/histogram: remove tail recursion
When running the same reproduction script as the previous patch, it turns out the stack is too small, which can be easily avoided. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
64c4e8bccd
commit
79cb2ebb92
@ -318,7 +318,9 @@ static int histogram_diff(xpparam_t const *xpp, xdfenv_t *env,
|
|||||||
{
|
{
|
||||||
struct region lcs;
|
struct region lcs;
|
||||||
int lcs_found;
|
int lcs_found;
|
||||||
int result = -1;
|
int result;
|
||||||
|
redo:
|
||||||
|
result = -1;
|
||||||
|
|
||||||
if (count1 <= 0 && count2 <= 0)
|
if (count1 <= 0 && count2 <= 0)
|
||||||
return 0;
|
return 0;
|
||||||
@ -355,11 +357,17 @@ static int histogram_diff(xpparam_t const *xpp, xdfenv_t *env,
|
|||||||
line2, lcs.begin2 - line2);
|
line2, lcs.begin2 - line2);
|
||||||
if (result)
|
if (result)
|
||||||
goto out;
|
goto out;
|
||||||
result = histogram_diff(xpp, env,
|
/*
|
||||||
lcs.end1 + 1, LINE_END(1) - lcs.end1,
|
* result = histogram_diff(xpp, env,
|
||||||
lcs.end2 + 1, LINE_END(2) - lcs.end2);
|
* lcs.end1 + 1, LINE_END(1) - lcs.end1,
|
||||||
if (result)
|
* lcs.end2 + 1, LINE_END(2) - lcs.end2);
|
||||||
goto out;
|
* but let's optimize tail recursion ourself:
|
||||||
|
*/
|
||||||
|
count1 = LINE_END(1) - lcs.end1;
|
||||||
|
line1 = lcs.end1 + 1;
|
||||||
|
count2 = LINE_END(2) - lcs.end2;
|
||||||
|
line2 = lcs.end2 + 1;
|
||||||
|
goto redo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
|
Reference in New Issue
Block a user