X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=xdiff%2Fxutils.c;h=21ab8e7e263983b54c07e44150cedc5c43963a35;hb=8c278abcbe35b23e9f93e99daf2144336fad1849;hp=afaada1edf72c8797d3d7bbd24303638accd6c24;hpb=4c61b7d15a6215fa4dffa33c37c3ef9df80d3f67;p=git.git diff --git a/xdiff/xutils.c b/xdiff/xutils.c index afaada1e..21ab8e7e 100644 --- a/xdiff/xutils.c +++ b/xdiff/xutils.c @@ -29,6 +29,19 @@ +long xdl_bogosqrt(long n) { + long i; + + /* + * Classical integer square root approximation using shifts. + */ + for (i = 1; n > 0; n >>= 2) + i <<= 1; + + return i; +} + + int xdl_emit_diffrec(char const *rec, long size, char const *pre, long psize, xdemitcb_t *ecb) { mmbuffer_t mb[3]; @@ -244,7 +257,7 @@ int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2, memcpy(buf, "@@ -", 4); nb += 4; - nb += xdl_num_out(buf + nb, c1 ? s1: 0); + nb += xdl_num_out(buf + nb, c1 ? s1: s1 - 1); if (c1 != 1) { memcpy(buf + nb, ",", 1); @@ -256,7 +269,7 @@ int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2, memcpy(buf + nb, " +", 2); nb += 2; - nb += xdl_num_out(buf + nb, c2 ? s2: 0); + nb += xdl_num_out(buf + nb, c2 ? s2: s2 - 1); if (c2 != 1) { memcpy(buf + nb, ",", 1);