Merge branch 'nd/diff-parseopt'
[gitweb.git] / xdiff / xhistogram.c
index fc2d3cd95d96dd2c2a6e2893a25151db50f6c91e..c7b35a9667f322c151bc8de276654ecd38974aef 100644 (file)
@@ -42,8 +42,6 @@
  */
 
 #include "xinclude.h"
-#include "xtypes.h"
-#include "xdiff.h"
 
 #define MAX_PTR        UINT_MAX
 #define MAX_CNT        UINT_MAX
@@ -318,7 +316,9 @@ static int histogram_diff(xpparam_t const *xpp, xdfenv_t *env,
 {
        struct region lcs;
        int lcs_found;
-       int result = -1;
+       int result;
+redo:
+       result = -1;
 
        if (count1 <= 0 && count2 <= 0)
                return 0;
@@ -355,11 +355,17 @@ static int histogram_diff(xpparam_t const *xpp, xdfenv_t *env,
                                                line2, lcs.begin2 - line2);
                        if (result)
                                goto out;
-                       result = histogram_diff(xpp, env,
-                                               lcs.end1 + 1, LINE_END(1) - lcs.end1,
-                                               lcs.end2 + 1, LINE_END(2) - lcs.end2);
-                       if (result)
-                               goto out;
+                       /*
+                        * result = histogram_diff(xpp, env,
+                        *            lcs.end1 + 1, LINE_END(1) - lcs.end1,
+                        *            lcs.end2 + 1, LINE_END(2) - lcs.end2);
+                        * 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: