Re: if statements vs. switch
Re: if statements vs. switch
- Subject: Re: if statements vs. switch
- From: "Clark S. Cox III" <email@hidden>
- Date: Thu, 05 Sep 2002 10:05:24 -0400
On 09/05/2002 09:50, "Stefan Pantos" <email@hidden> wrote:
>
Hi,
>
I should compile to more efficent code as it uses a jump with an offset to
>
find the correct one instead of a compare jump for each test. Also the line
>
[prefs integerForKey:@"ControlsDisplaySide"] isn't re-evaluated each time.
>
When optimised it would probably be like this for a if:
>
>
value = [prefs integerForKey:@"ControlsDisplaySide"];
>
if (value == 0)
>
setFrameTopLeftPoint:topLeft];
>
else if (value == 1)
>
setFrameTopLeftPoint:bottomLeft];
>
else if (value == 2)
>
setFrameTopLeftPoint:topRight];
>
else if (value == 3)
>
setFrameTopLeftPoint:bottomRight];
Wrong. Since [prefs integerForKey:@"ControlsDisplaySide"] is a method
call, it MUST be called each time, because the compiler has no way of
knowing what side-effects this method call may have. Any compiler that
optimizes away a method call in this fashion is broken.
--
http://homepage.mac.com/clarkcox3/
Clark S. Cox III
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.