This patch for the Objective-C compiler gets rid of another case where we'd create a temporary tree chain with a copy of all the instance variables of a class just to do a simple check on them.
The check is the one to check the scope of the instance variable that is being accessed; without this patch, the check requires copying all the instance variables for the class on a temporary tree chain. With this patch, the check is done (as you'd expect) on the instance variables themselves, without copying them. This is obviously faster; on the other hand, the typical GNUstep-based ObjC file has classes with few instance variables (maybe 10 or 20) and only accesses instance variables up to a few hundred times per file, so the speedup is only of the order of 0.1% to 0.2% even with -fsyntax-only. Of course, in unusual cases (ie, classes with many instance variables, and a big file accessing instance variables lots of times) the speedup may be bigger. Ok to commit ? Thanks Index: ChangeLog =================================================================== --- ChangeLog (revision 172511) +++ ChangeLog (working copy) @@ -1,5 +1,10 @@ 2011-04-15 Nicola Pero <nicola.p...@meta-innovation.com> + * objc-act.c (ivar_of_class): New. + (objc_is_public): Use ivar_of_class. + +2011-04-15 Nicola Pero <nicola.p...@meta-innovation.com> + * objc-act.c (objc_get_interface_ivars): Removed. (objc_detect_field_duplicates): New. (hash_instance_variable): New. Index: objc-act.c =================================================================== --- objc-act.c (revision 172511) +++ objc-act.c (working copy) @@ -6367,6 +6367,35 @@ is_private (tree decl) DECL_NAME (decl))); } +/* Searches all the instance variables of 'klass' and of its + superclasses for an instance variable whose name (identifier) is + 'ivar_name_ident'. Return the declaration (DECL) of the instance + variable, if found, or NULL_TREE, if not found. */ +static inline tree +ivar_of_class (tree klass, tree ivar_name_ident) +{ + /* First, look up the ivar in CLASS_RAW_IVARS. */ + tree decl_chain = CLASS_RAW_IVARS (klass); + + for ( ; decl_chain; decl_chain = DECL_CHAIN (decl_chain)) + if (DECL_NAME (decl_chain) == ivar_name_ident) + return decl_chain; + + /* If not found, search up the class hierarchy. */ + while (CLASS_SUPER_NAME (klass)) + { + klass = lookup_interface (CLASS_SUPER_NAME (klass)); + + decl_chain = CLASS_RAW_IVARS (klass); + + for ( ; decl_chain; decl_chain = DECL_CHAIN (decl_chain)) + if (DECL_NAME (decl_chain) == ivar_name_ident) + return decl_chain; + } + + return NULL_TREE; +} + /* We have an instance variable reference;, check to see if it is public. */ int @@ -6397,7 +6426,7 @@ objc_is_public (tree expr, tree identifier) return 0; } - if ((decl = is_ivar (get_class_ivars (klass, true), identifier))) + if ((decl = ivar_of_class (klass, identifier))) { if (TREE_PUBLIC (decl)) return 1;