discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Accessing array members without the use of objectAtIndex


From: David Chisnall
Subject: Re: Accessing array members without the use of objectAtIndex
Date: Sat, 14 Apr 2018 13:52:46 +0100

On 14 Apr 2018, at 13:39, Andreas Fink <afink@list.fink.org> wrote:
> 
> This is mainly a question of if the compiler is able to do this newer ObjC2.0 
> syntax.
> clang does it nicely. Not sure if gcc can these days. Some older gcc versions 
> where for sure not capable which was the reason for me to switch all to 
> clang, given the new syntaxes saves you a lot of writing.
> 
> The syntax 
> 
>        id a =  someobject[x] ;
> 
> will translate into a call like this
> 
>       a =[someobject objectForKeyedSubscript:x];
> 
> The syntax
> 
>       someobject[x]  = a;
> 
> 
> will translate into a call like this
> 
>       [someobject setObject:a for keyedSubscript:x]

This is only true if x is an object type.  If x is an integer type then it 
translates into [someobject objectAtIndexedSubscript: x].  Currently, in 
GNUstep, -objectAtIndexedSubscript: is implemented by only NSArray and calls 
[self objectAtIndex:] (which the concrete subclass of NSArray then implements), 
so when you use the subscripting you are actually getting less efficient code 
than if you use -objectAtIndex:.

So, uh, yay?

David




reply via email to

[Prev in Thread] Current Thread [Next in Thread]