Hello,

On 12/5/06, yuhang <[EMAIL PROTECTED]> wrote:
> ======= 2006-12-04 21:29:06 Alexander wrote =======
> >But is there any reason to change while() {} to do {} while()? I think we 
> >should
> >check pNextAddr && (numAddresses<maxAddresses) right after we have got
> >first pNextAddr:
> >PIP_ADDR_STRING pNextAddr = &pNextInfoRecord->IpAddressList;
> = = = = = = = = = = = = = = = = = = = =
>
> Generally speeking, while(){} is safer than do {} while() and while() {} will
> certainly work in this case.
>
>Well, in this case, while(){} and do{}while() do the same thing. I
can prove that.
>Right after "PIP_ADDR_STRING pNextAddr =
&pNextInfoRecord->IpAddressList;" and just
>before entering the inner loop, (numAddresses<maxAddresses) is always
true, since it
>has been checked in the outer loop: while (pNextInfoRecord &&
(numAddresses<maxAddresses)).
>And the address of (pNextInfoRecord->IpAddressList) is not NULL. So
pNextAddr must NOT
>be NULL. It then follows that (pNextAddr &&
(numAddresses<maxAddresses)) is always true
>when we first enter the inner loop, thus concludes that while(){} and
do{}while() do the
>same thing in this case.
>
>The reason why i preffer do{}while() than while(){} is that usually
compiler may generate
>one more conditional jump instruction if while(){} is used. But in
this case, we won't see
>the difference in performance whether we use do{}while() or we use
while(). Both will work
>well.
Good argumentation.
I prefer while() {} here, because it reads better -- you see condition before
you begin reading loop body. There are many very non-optimal places in the
library, so such a small optimixation does not make sense. I prefer readability
to small optimization.

Commited as r8195, thanks for fix. :)

-- 
Regards,
Alexander Chemeris.
_______________________________________________
sipxtapi-dev mailing list
[email protected]
List Archive: http://list.sipfoundry.org/archive/sipxtapi-dev/

Reply via email to