Instead of (UINT)((j/2)+0.5)

Better (UINT)((j+1)>>1)

Much faster, and avoids unnecessary FPU and division usage. Many compilers will translate /2 to >>1, but none will change the way of rounding.

 

Jose Catena

DIGIWAVES S.L.

 

From: ros-dev-bounces@reactos.org [mailto:ros-dev-bounces@reactos.org] On Behalf Of Wladimir A. Jimenez B.
Sent: Friday, 11 September, 2009 16:56
To: ReactOS Development List
Subject: Re: [ros-dev] [ros-diffs] [sginsberg] 42829: - svchost: #ifdef _MSC_VER doesn't mean "using Microsoft's headers" anymore - ddraw, imm32, msxml3, oleaut32, riched20: Include typeof.h for typeof emulation when compiling under MSVC and remove from React

 

2009/8/23 Filip Navara <filip.navara@gmail.com>

On Fri, Aug 21, 2009 at 5:57 PM, <sginsberg@svn.reactos.org> wrote:
> --- trunk/reactos/drivers/network/ndis/ndis/config.c [iso-8859-1] (original)
> +++ trunk/reactos/drivers/network/ndis/ndis/config.c [iso-8859-1] Fri Aug 21 17:57:26 2009
> @@ -705,7 +705,14 @@
>
>     while (j < str.Length && str.Buffer[j] != '\0') j++;
>
> -    *NetworkAddressLength = (UINT)((j/2)+0.5);
> +    if ((j % 2) == 0)
> +    {
> +        *NetworkAddressLength = (UINT)(j/2);
> +    }
> +    else
> +    {
> +        *NetworkAddressLength = (UINT)((j/2)+1);
> +    }

Why not use  *NetworkAddressLength = (UINT)((j+1)/2); unconditionally?


>
>     if ((*NetworkAddressLength) == 0)
>     {
>

F.

_______________________________________________
Ros-dev mailing list
Ros-dev@reactos.org
http://www.reactos.org/mailman/listinfo/ros-dev




--
----------------------------------------
Wladimir A. Jiménez B.
http://www.kasbeel.cl
Linux User # 444661
Ubuntu User # 19201