This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[PATCH] Java: minor fix.



This patch makes gcj use a hash table in order to remember already
searched interfaces when gathering method invocation candidates. I'm
checking it in.

./A

2000-04-05  Alexandre Petit-Bianco  <apbianco@cygnus.com>

	* class.c: (java_hash_hash_tree_node): Renamed from `decl_hash',
	made global.
	(java_hash_compare_tree_node): Renamed from `decl_compare, made
	global.
	(add_method_1): Use `java_hash_hash_tree_node' and
	`java_hash_compare_tree_node'.
	* java-tree.h: (java_hash_hash_tree_node): Prototyped.
	(java_hash_compare_tree_node): Likewise.
	* parse.y (find_applicable_accessible_methods_list): Create,
	delete and use a hash table to remember already searched interfaces.

Index: class.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/class.c,v
retrieving revision 1.63
diff -u -p -r1.63 class.c
--- class.c	2000/04/04 20:40:19	1.63
+++ class.c	2000/04/05 23:24:41
@@ -594,22 +594,25 @@ init_test_hash_newfunc (entry, table, st
   return (struct hash_entry *) ret;
 }
 
-static unsigned long
-decl_hash (k)
+/* Hash table helpers. Also reused in find_applicable_accessible_methods_list
+   (parse.y). The hash of a tree node is it's pointer value,
+   comparison is direct. */
+
+unsigned long
+java_hash_hash_tree_node (k)
      hash_table_key k;
 {
   return (long) k;
 }
 
-static boolean
-decl_compare (k1, k2)
+boolean
+java_hash_compare_tree_node (k1, k2)
      hash_table_key k1;
      hash_table_key k2;
 {
   return ((char*) k1 == (char*) k2);
 }
 
-
 tree
 add_method_1 (handle_class, access_flags, name, function_type)
      tree handle_class;
@@ -632,8 +635,8 @@ add_method_1 (handle_class, access_flags
 
   /* Initialize the static initializer test table.  */
   hash_table_init (&DECL_FUNCTION_INIT_TEST_TABLE (fndecl),
-		   init_test_hash_newfunc, decl_hash,
-		   decl_compare);
+		   init_test_hash_newfunc, java_hash_hash_tree_node, 
+		   java_hash_compare_tree_node);
 
   TREE_CHAIN (fndecl) = TYPE_METHODS (handle_class);
   TYPE_METHODS (handle_class) = fndecl;
Index: java-tree.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/java-tree.h,v
retrieving revision 1.63
diff -u -p -r1.63 java-tree.h
--- java-tree.h	2000/03/25 18:34:13	1.63
+++ java-tree.h	2000/04/05 23:24:44
@@ -753,6 +753,9 @@ void java_debug_context PARAMS ((void));
 void safe_layout_class PARAMS ((tree));
 
 extern tree get_boehm_type_descriptor PARAMS ((tree));
+extern unsigned long java_hash_hash_tree_node PARAMS ((hash_table_key));
+extern boolean java_hash_compare_tree_node PARAMS ((hash_table_key, 
+						    hash_table_key));
 
 /* We use ARGS_SIZE_RTX to indicate that gcc/expr.h has been included
    to declare `enum expand_modifier'. */
Index: parse.y
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/parse.y,v
retrieving revision 1.147
diff -u -p -r1.147 parse.y
--- parse.y	2000/04/04 20:40:20	1.147
+++ parse.y	2000/04/05 23:25:18
@@ -9839,22 +9839,29 @@ find_applicable_accessible_methods_list 
   /* Search interfaces */
   if (CLASS_INTERFACE (TYPE_NAME (class)))
     {
-      static tree searched_interfaces = NULL_TREE;
+      static struct hash_table t, *searched_interfaces = NULL;
       static int search_not_done = 0;
       int i, n;
       tree basetype_vec = TYPE_BINFO_BASETYPES (class);
 
-      /* Have we searched this interface already? We shoud use a hash
-         table, FIXME */
+      /* Search in the hash table, otherwise create a new one if
+         necessary and insert the new entry. */
+
       if (searched_interfaces)
-	{  
-	  tree current;  
-	  for (current = searched_interfaces; 
-	       current; current = TREE_CHAIN (current))
-	    if (TREE_VALUE (current) == class)
-	      return NULL;
+	{
+	  if (hash_lookup (searched_interfaces, 
+			   (const hash_table_key) class, FALSE, NULL))
+	    return NULL;
 	}
-      searched_interfaces = tree_cons (NULL_TREE, class, searched_interfaces);
+      else
+	{
+	  hash_table_init (&t, hash_newfunc, java_hash_hash_tree_node,
+			   java_hash_compare_tree_node);
+	  searched_interfaces = &t;
+	}
+
+      hash_lookup (searched_interfaces, 
+		   (const hash_table_key) class, TRUE, NULL);
 
       search_applicable_methods_list (lc, TYPE_METHODS (class), 
 				      name, arglist, &list, &all_list);
@@ -9879,7 +9886,8 @@ find_applicable_accessible_methods_list 
 	    search_applicable_methods_list (lc, 
 					    TYPE_METHODS (object_type_node),
 					    name, arglist, &list, &all_list);
-	  searched_interfaces = NULL_TREE;  
+	  hash_table_free (searched_interfaces);
+	  searched_interfaces = NULL;  
 	}
     }
   /* Search classes */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]