Re: Referencing struct fields in C
Re: Referencing struct fields in C
- Subject: Re: Referencing struct fields in C
- From: Cem Karan <email@hidden>
- Date: Mon, 30 May 2011 11:23:13 -0400
> From: Oleg Krupnov <email@hidden>
> Date: May 30, 2011 9:30:22 AM EDT
> To: Graham Cox <email@hidden>
> Cc: Cocoa-Dev List <email@hidden>
> 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@hidden)
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:
This email sent to email@hidden