> From: Oleg Krupnov <[email protected]>
> Date: May 30, 2011 9:30:22 AM EDT
> To: Graham Cox <[email protected]>
> Cc: Cocoa-Dev List <[email protected]>
> Subject: Re: Referencing struct fields in C
<<SNIP>>
> One thing that bothers me though. How the compiler will understand
> that the state is loop-invariant? Should I necessarily declare the
> checked boolean state as a local stack variable (unlike to a class
> member variable that may change as a side-effect, if foo() was a class
> method)?
>
> for example
> - (void)foo
> {
> bool xOrY = m_isXOrY;
> for (int i = 0; i < N; ++i)
> {
> if (xOrY)
> {
> int value = a[i].y;
> ...
> }
> else
> {
> int value = a[i].y;
> ...
> }
> }
> }
>
> Would this suffice?
>
> Thanks!
Oleg, have you tried looking at the assembly output from the compiler? It
might be doing something stranger than that. One possibility is that it
coalesces all code into two chunks, one for when xOrY is true, and the other
when its false, in which case there is exactly one branch being evaluated.
That said, if you're really trying to tweak your performance, you're probably
better off looking into -fprofile-generate and -fprofile-use (in gcc) than what
you're suggesting. Hand tweaking WITHOUT adequate profiling as you're
suggesting is the absolute bane of programming; you'll be spending a lot of
time 'optimizing' without really knowing if you're improving things or not...
Thanks,
Cem Karan_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]