• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: if statements vs. switch
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Re: if statements vs. switch (From: Stefan Pantos <email@hidden>)

  • Prev by Date: Re: if statements vs. switch
  • Next by Date: Re: Launching an App without NSWorkspace?
  • Previous by thread: Re: if statements vs. switch
  • Next by thread: Re: if statements vs. switch
  • Index(es):
    • Date
    • Thread