Re: loop efficiency & messages
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