• 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: loop efficiency & messages
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: loop efficiency & messages


  • Subject: Re: loop efficiency & messages
  • From: "Corey O'Connor" <email@hidden>
  • Date: Tue, 22 Mar 2005 13:10:10 -0800

On Tue, 22 Mar 2005 21:49:52 +0100, Ondra Cada <email@hidden> wrote:
> > Does compiler optimize this similar to a C++ inline so that count is
> > just stored in a register, or does a message sequence happen each
> > time?
>
> Very bad idea. If it did this "optimization", it would be a *very grave
> bug*. There's no way the compiler can ever know the value returned
> would not change the next time the message is sent.

I believe, in C++, if you had something like this:

UInt16 Foo(const UInt16 inX, const UInt16 inY) __attribute__ ((pure));

UInt16 Foo(const UInt16 inX, const UInt16 inY)
{
    return inX + inY;
}

void DoSomething(const UInt16 inCount)
{
    for(UInt16 x = 0; x < Foo(inCount, inCount); ++x)
    {
         DoSomethingElse(x);
    }
}

The compiler will have enough information to optimize the call to Foo
into a single call cached to a register.

Is there anyway to declare an objective-c function to be, similarly, a
"pure" function?

--
-Corey O'Connor
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: loop efficiency & messages
      • From: Ondra Cada <email@hidden>
References: 
 >loop efficiency & messages (From: Mark Dawson <email@hidden>)
 >Re: loop efficiency & messages (From: Ondra Cada <email@hidden>)

  • Prev by Date: Re: Creating a shlb
  • Next by Date: NSTableView and Bindings
  • Previous by thread: Re: loop efficiency & messages
  • Next by thread: Re: loop efficiency & messages
  • Index(es):
    • Date
    • Thread