What cured me of optimization-itis was this entry in ridiculousfish's 
ridiculously cool blog:

http://ridiculousfish.com/blog/archives/2010/07/23/will-it-optimize/#fish_made_a_mess

--Rob


>> 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)?
> 
> No, just leave it. It can see that it's loop-invariant because it's passed in 
> as a value to the function - within the function nothing ever changes its 
> value. Copying it to another variable might do more harm than good (though I 
> suspect the optimizer wouldn't be fazed by that).
> 
> Another way to "optimise" in a simple manner is just to have two loops, one 
> for true and one for false. Effectively that's how the optimizer rewrites 
> your code anyway.
> 
> --Graham
> 

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to