Skip to content

Commit f7466e9

Browse files
stefanbellergitster
authored andcommitted
create_delta_index: simplify condition always evaluating to true
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 506049c (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 <[email protected]> Acked-by: Nicolas Pitre <[email protected]> Acked-by: Philip Oakley <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent edca415 commit f7466e9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

diff-delta.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize)
155155
entries = 0xfffffffeU / RABIN_WINDOW;
156156
}
157157
hsize = entries / 4;
158-
for (i = 4; (1u << i) < hsize && i < 31; i++);
158+
for (i = 4; (1u << i) < hsize; i++);
159159
hsize = 1 << i;
160160
hmask = hsize - 1;
161161

0 commit comments

Comments
 (0)