]> git.ipfire.org Git - thirdparty/git.git/commit - shallow.c
shallow.c: bit manipulation tweaks
authorRasmus Villemoes <rv@rasmusvillemoes.dk>
Tue, 6 Dec 2016 12:53:38 +0000 (19:53 +0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 7 Dec 2016 23:44:31 +0000 (15:44 -0800)
commit1127b3ced55b97229c55ff0c7585b284e3551a9e
tree670aac6ae5864183d3b8672a2cdf563309f258e4
parent381aa8e73070646933520e1133a81ab4ba383891
shallow.c: bit manipulation tweaks

First of all, 1 << 31 is technically undefined behaviour, so let's just
use an unsigned literal.

If i is 'signed int' and gcc doesn't know that i is positive, gcc
generates code to compute the C99-mandated values of "i / 32" and "i %
32", which is a lot more complicated than simple a simple shifts/mask.

The only caller of paint_down actually passes an "unsigned int" value,
but the prototype of paint_down causes (completely well-defined)
conversion to signed int, and gcc has no way of knowing that the
converted value is non-negative. Just make the id parameter unsigned.

In update_refstatus, the change in generated code is much smaller,
presumably because gcc is smart enough to see that i starts as 0 and is
only incremented, so it is allowed (per the UD of signed overflow) to
assume that i is always non-negative. But let's just help less smart
compilers generate good code anyway.

Signed-off-by: Rasmus Villemoes <rv@rasmusvillemoes.dk>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
shallow.c