- Make objc_retain() check for stack blocks and implicitly copy them. This fixes the case where a block pointer is stored in an object-typed variable and is assigned.
- Tweak objc_retainAutoreleaseReturnValue() so that the ARC optimiser doesn't detect that the body looks like a call to objc_retainAutoreleaseReturnValue() and replace it with an infinitely recursive call.
The second fix now means that arc.m will compile with clang without producing a function that calls itself.
In a simple example:
- foo { return self; }
void someFunction(void)
{
id a = foo;
...
}
In ARC mode, this expands to:
- foo { return objc_retainAutoreleaseReturnValue(self); }
void someFunction(void)
{
id a = objc_retainAutoreleasedReturnValue(foo);
...
}
In the slow path, this is equivalent to:
- foo { return [[self retain] autorelease]; }
void someFunction(void)
{
id a = [foo retain];
...
[a release];
}
The fast path skips the autorelease / retain pair. The return value is stored
in thread-local storage temporarily and then retrieved, the retain balancing
out the autorelease.
This gives a 50% speedup on a single thread. It also avoids some atomic
operations.
Weak references are still not supported, but code that doesn't use them (i.e. any code that wants to be compatible with OS X 10.6) will work fine.
The current implementation is VERY inefficient and has a large number of missed optimisation opportunities: this is the 'make it right' phase, and should be almost equivalent to explicit retain / release code.