Re: [PATCH] use DIV_ROUND_UP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 8 July 2017 at 12:35, René Scharfe <l.s.r@xxxxxx> wrote:
> Convert code that divides and rounds up to use DIV_ROUND_UP to make the
> intent clearer and reduce the number of magic constants.
...
> diff --git a/sha1_name.c b/sha1_name.c
> index e7f7b12ceb..8c513dbff6 100644
> --- a/sha1_name.c
> +++ b/sha1_name.c
> @@ -492,7 +492,7 @@ int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len)
>                  * together we need to divide by 2; but we also want to round
>                  * odd numbers up, hence adding one before dividing.
>                  */
> -               len = (len + 1) / 2;
> +               len = DIV_ROUND_UP(len, 2);

Since the addition is now an implementation detail of DIV_ROUND_UP,
should the comment be adjusted, maybe simply by removing ", hence
adding one before dividing"?

Or perhaps even better, "... divide by 2; but since len might be odd,
we need to make sure we round up as we divide". My thinking being,
we're not actually rounding odd numbers up (presumably to even
numbers), but we're rounding the result of the division up (to the
smallest larger integer).




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux