malaba
malaba

Reputation: 654

local variable, optimisation and ARC

Given NSArray *tagsArray and NSMutableDictionary *cache not empty.

This:

for (Tag *tag in tagsArray) {
    NSString *name = tag.name;
    [cache setObject:tag forKey:name];
}

should not be slower than this:

for (Tag *tag in tagsArray) {
    [cache setObject:tag forKey:tag.name];
}

?

the __strong var 'name' would not use an implicit retain/release by ARC ? The compiler will actually generate the second from the first ?

Upvotes: 2

Views: 339

Answers (2)

Hugo the Lee
Hugo the Lee

Reputation: 101

If ChildClass objecA, objecB.... has an instance variable, and ParentClass tries to assign the ChildClass's instance variable (which is an instance variable of ParentClass and strong pointer),

then ChildClass' object acts like the same object. Although it is not the same. Definitely not same.

Upvotes: 0

art-divin
art-divin

Reputation: 1645

Yes, it IS the same for ARC, because there's no other code that interacts with "name" variable in first example.

For future, try to understand that ARC modifies your code for better performance and optimization, and not vice versa.

Here's the link with entire documentation for ARC - must know - http://clang.llvm.org/docs/AutomaticReferenceCounting.html

Upvotes: 1

Related Questions