create_delta_index: simplify condition always evaluating to true
authorStefan Beller <stefanbeller@googlemail.com>
Fri, 16 Aug 2013 21:22:37 +0000 (23:22 +0200)
committerJunio C Hamano <gitster@pobox.com>
Sun, 18 Aug 2013 19:56:23 +0000 (12:56 -0700)
The code sequence ' (1u << i) < hsize && i < 31 ' is a multi step
process, whose first step requires that 'i' is already less that 31,
otherwise the result (1u << i) is undefined (and 'undef_val < hsize'
can therefore be assumed to be 'false'), and so the later test i < 31
can always be optimized away as dead code ('i' is already less than 31,
or the short circuit 'and' applies).

So we need to get rid of that code. One way would be to exchange the
order of the conditions, so the expression 'i < 31 && (1u << i) < hsize'
would remove that optimized unstable code already.

However when checking the previous lines in that function, we can deduce
that 'hsize' must always be smaller than (1u<<31), since 506049c7df2c6
(fix >4GiB source delta assertion failure), because 'entries' is
capped at an upper bound of 0xfffffffeU, so 'hsize' contains a maximum
value of 0x3fffffff, which is smaller than (1u<<31), so the value of
'i' will never be larger than 31 and we can remove that condition
entirely.

Signed-off-by: Stefan Beller <stefanbeller@googlemail.com>
Acked-by: Nicolas Pitre <nico@fluxnic.net>
Acked-by: Philip Oakley <philipoakley@iee.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff-delta.c
index 93385e12baa0d90ae475bd02500edf5ddcce320c..3797ce6041981d1facda44d3a95d4448dbb8a091 100644 (file)
@@ -155,7 +155,7 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize)
                entries = 0xfffffffeU / RABIN_WINDOW;
        }
        hsize = entries / 4;
-       for (i = 4; (1u << i) < hsize && i < 31; i++);
+       for (i = 4; (1u << i) < hsize; i++);
        hsize = 1 << i;
        hmask = hsize - 1;