diff mbox

Objc - merged classname hashtable patch from apple/trunk

Message ID 1287597845.218432219@192.168.2.230
State New
Headers show

Commit Message

Nicola Pero Oct. 20, 2010, 6:04 p.m. UTC
This merge from FSF apple/trunk provides a (small) speedup for compiling Objective-C.

Committed to trunk (preapproved by Mike).

Thanks

2010-10-20  Nicola Pero  <nicola.pero@meta-innovation.com>

        Merge from 'apple/trunk' branch on FSF servers.  Obvious updates
        to gcc_alloc_xxx calls in hash_init and hash_class_name_enter to
        get it to compile in the current trunk.

        2006-01-27 Fariborz Jahanian <fjahanian@apple.com>

        Radar 4345837
        * objc/objc-act.c (hash_class_name_enter): New.
        (hash_class_name_lookup): New.
        (objc_declare_alias): Enter alias name into hash table.
        (objc_declare_class): Enter class name into hash table.
        (objc_is_class_name): Do a hash look up of class name.
        (hash_init): Initialize the two new hash tables.
        * objc-act.h: Added cls_name_hash_list and als_name_hash_list
        declarations, removed class_chain and alias_chain.
diff mbox

Patch

Index: gcc/objc/objc-act.c
===================================================================
--- gcc/objc/objc-act.c	(revision 165714)
+++ gcc/objc/objc-act.c	(working copy)
@@ -211,6 +211,14 @@  static const char *synth_id_with_class_suffix (con
 hash *nst_method_hash_list = 0;
 hash *cls_method_hash_list = 0;
 
+/* Hash tables to manage the global pool of class names.  */
+
+hash *cls_name_hash_list = 0;
+hash *als_name_hash_list = 0;
+
+static void hash_class_name_enter (hash *, tree, tree);
+static hash hash_class_name_lookup (hash *, tree);
+
 static hash hash_lookup (hash *, tree);
 static tree lookup_method (tree, tree);
 static tree lookup_method_static (tree, tree, int);
@@ -3586,7 +3594,8 @@  objc_declare_alias (tree alias_ident, tree class_i
 #ifdef OBJCPLUS
       pop_lang_context ();
 #endif
-      alias_chain = tree_cons (underlying_class, alias_ident, alias_chain);
+      hash_class_name_enter (als_name_hash_list, alias_ident, 
+			     underlying_class);
     }
 }
 
@@ -3628,7 +3637,7 @@  objc_declare_class (tree ident_list)
 	  record = xref_tag (RECORD_TYPE, ident);
 	  INIT_TYPE_OBJC_INFO (record);
 	  TYPE_OBJC_INTERFACE (record) = ident;
-	  class_chain = tree_cons (NULL_TREE, ident, class_chain);
+	  hash_class_name_enter (cls_name_hash_list, ident, NULL_TREE);
 	}
     }
 }
@@ -3636,7 +3645,7 @@  objc_declare_class (tree ident_list)
 tree
 objc_is_class_name (tree ident)
 {
-  tree chain;
+  hash target;
 
   if (ident && TREE_CODE (ident) == IDENTIFIER_NODE
       && identifier_global_value (ident))
@@ -3661,16 +3670,15 @@  objc_is_class_name (tree ident)
   if (lookup_interface (ident))
     return ident;
 
-  for (chain = class_chain; chain; chain = TREE_CHAIN (chain))
-    {
-      if (ident == TREE_VALUE (chain))
-	return ident;
-    }
+  target = hash_class_name_lookup (cls_name_hash_list, ident);
+  if (target)
+    return target->key;
 
-  for (chain = alias_chain; chain; chain = TREE_CHAIN (chain))
+  target = hash_class_name_lookup (als_name_hash_list, ident);
+  if (target)
     {
-      if (ident == TREE_VALUE (chain))
-	return TREE_PURPOSE (chain);
+      gcc_assert (target->list && target->list->value);
+      return target->list->value;
     }
 
   return 0;
@@ -7483,11 +7491,62 @@  hash_init (void)
   nst_method_hash_list = ggc_alloc_cleared_vec_hash (SIZEHASHTABLE);
   cls_method_hash_list = ggc_alloc_cleared_vec_hash (SIZEHASHTABLE);
 
+  cls_name_hash_list = ggc_alloc_cleared_vec_hash (SIZEHASHTABLE);
+  als_name_hash_list = ggc_alloc_cleared_vec_hash (SIZEHASHTABLE);
+
   /* Initialize the hash table used to hold the constant string objects.  */
   string_htab = htab_create_ggc (31, string_hash,
 				   string_eq, NULL);
 }
 
+/* This routine adds sel_name to the hash list. sel_name  is a class or alias
+   name for the class. If alias name, then value is its underlying class.
+   If class, the value is NULL_TREE. */
+
+static void
+hash_class_name_enter (hash *hashlist, tree sel_name, tree value)
+{
+  hash obj;
+  int slot = hash_func (sel_name) % SIZEHASHTABLE;
+
+  obj = ggc_alloc_hashed_entry ();
+  if (value != NULL_TREE)
+    {
+      /* Save the underlying class for the 'alias' in the hash table */
+      attr obj_attr = ggc_alloc_hashed_attribute ();
+      obj_attr->value = value;
+      obj->list = obj_attr;
+    }
+  else
+    obj->list = 0;
+  obj->next = hashlist[slot];
+  obj->key = sel_name;
+
+  hashlist[slot] = obj;         /* append to front */
+
+}
+
+/*
+   Searches in the hash table looking for a match for class or alias name.
+*/
+
+static hash
+hash_class_name_lookup (hash *hashlist, tree sel_name)
+{
+  hash target;
+
+  target = hashlist[hash_func (sel_name) % SIZEHASHTABLE];
+
+  while (target)
+    {
+      if (sel_name == target->key)
+	return target;
+
+      target = target->next;
+    }
+  return 0;
+}
+
 /* WARNING!!!!  hash_enter is called with a method, and will peek
    inside to find its selector!  But hash_lookup is given a selector
    directly, and looks for the selector that's inside the found
Index: gcc/objc/ChangeLog
===================================================================
--- gcc/objc/ChangeLog	(revision 165714)
+++ gcc/objc/ChangeLog	(working copy)
@@ -1,5 +1,23 @@ 
 2010-10-20  Nicola Pero  <nicola.pero@meta-innovation.com>
 
+	Merge from 'apple/trunk' branch on FSF servers.  Obvious updates
+	to gcc_alloc_xxx calls in hash_init and hash_class_name_enter to
+	get it to compile in the current trunk.
+
+	2006-01-27 Fariborz Jahanian <fjahanian@apple.com>
+
+	Radar 4345837
+	* objc/objc-act.c (hash_class_name_enter): New.
+	(hash_class_name_lookup): New.
+	(objc_declare_alias): Enter alias name into hash table.
+	(objc_declare_class): Enter class name into hash table.
+	(objc_is_class_name): Do a hash look up of class name.
+	(hash_init): Initialize the two new hash tables.
+	* objc-act.h: Added cls_name_hash_list and als_name_hash_list 
+	declarations, removed class_chain and alias_chain.	
+
+2010-10-20  Nicola Pero  <nicola.pero@meta-innovation.com>
+
 	* objc-lang.c (finish_file): Removed.
 	* objc-act.c (objc_finish_file): Renamed to
 	objc_write_global_declarations.  Do not try to instantiate C++
Index: gcc/objc/objc-act.h
===================================================================
--- gcc/objc/objc-act.h	(revision 165714)
+++ gcc/objc/objc-act.h	(working copy)
@@ -156,6 +156,9 @@  struct GTY(()) hashed_entry {
 extern GTY ((length ("SIZEHASHTABLE"))) hash *nst_method_hash_list;
 extern GTY ((length ("SIZEHASHTABLE"))) hash *cls_method_hash_list;
 
+extern GTY ((length ("SIZEHASHTABLE"))) hash *cls_name_hash_list;
+extern GTY ((length ("SIZEHASHTABLE"))) hash *als_name_hash_list;
+
 #define SIZEHASHTABLE		257
 
 /* Objective-C/Objective-C++ @implementation list.  */
@@ -200,8 +203,6 @@  enum objc_tree_index
     OCTI_NST_TYPE,
     OCTI_PROTO_TYPE,
 
-    OCTI_CLS_CHAIN,
-    OCTI_ALIAS_CHAIN,
     OCTI_INTF_CHAIN,
     OCTI_PROTO_CHAIN,
     OCTI_IMPL_CHAIN,
@@ -338,8 +339,6 @@  extern GTY(()) tree objc_global_trees[OCTI_MAX];
 	(TREE_CODE (TYPE) == POINTER_TYPE				\
 	 && TREE_TYPE (TYPE) == objc_super_template)
 
-#define class_chain		objc_global_trees[OCTI_CLS_CHAIN]
-#define alias_chain		objc_global_trees[OCTI_ALIAS_CHAIN]
 #define interface_chain		objc_global_trees[OCTI_INTF_CHAIN]
 #define protocol_chain		objc_global_trees[OCTI_PROTO_CHAIN]
 #define implemented_classes	objc_global_trees[OCTI_IMPL_CHAIN]