diff options
Diffstat (limited to 'gcc/java')
-rw-r--r-- | gcc/java/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/java/Make-lang.in | 6 | ||||
-rw-r--r-- | gcc/java/jcf-io.c | 43 |
3 files changed, 37 insertions, 19 deletions
diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog index 96c9df9..190d48c 100644 --- a/gcc/java/ChangeLog +++ b/gcc/java/ChangeLog @@ -1,3 +1,10 @@ +2012-10-01 Lawrence Crowl <crowl@google.com> + + * Make-lang.in (JAVA_OBJS): Add dependence on hash-table.o. + (JCFDUMP_OBJS): Add dependence on hash-table.o. + (jcf-io.o): Add dependence on hash-table.h. + * jcf-io.c (memoized_class_lookups): Change to use type-safe hash table. + 2012-09-24 Lawrence Crowl <crowl@google.com> * decl.c (java_init_decl_processing): Change to new double_int API. diff --git a/gcc/java/Make-lang.in b/gcc/java/Make-lang.in index 77de0d3..390782d 100644 --- a/gcc/java/Make-lang.in +++ b/gcc/java/Make-lang.in @@ -83,10 +83,10 @@ JAVA_OBJS = java/class.o java/decl.o java/expr.o \ java/zextract.o java/jcf-io.o java/win32-host.o java/jcf-parse.o java/mangle.o \ java/mangle_name.o java/builtins.o java/resource.o \ java/jcf-depend.o \ - java/jcf-path.o java/boehm.o java/java-gimplify.o + java/jcf-path.o java/boehm.o java/java-gimplify.o hash-table.o JCFDUMP_OBJS = java/jcf-dump.o java/jcf-io.o java/jcf-depend.o java/jcf-path.o \ - java/win32-host.o java/zextract.o ggc-none.o + java/win32-host.o java/zextract.o ggc-none.o hash-table.o JVGENMAIN_OBJS = java/jvgenmain.o java/mangle_name.o @@ -326,7 +326,7 @@ java/java-gimplify.o: java/java-gimplify.c $(CONFIG_H) $(SYSTEM_H) \ # jcf-io.o needs $(ZLIBINC) added to cflags. CFLAGS-java/jcf-io.o += $(ZLIBINC) java/jcf-io.o: java/jcf-io.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \ - $(JAVA_TREE_H) java/zipfile.h + $(JAVA_TREE_H) java/zipfile.h $(HASH_TABLE_H) # jcf-path.o needs a -D. CFLAGS-java/jcf-path.o += \ diff --git a/gcc/java/jcf-io.c b/gcc/java/jcf-io.c index 0fe30b3..97a3c0f 100644 --- a/gcc/java/jcf-io.c +++ b/gcc/java/jcf-io.c @@ -31,7 +31,7 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */ #include "jcf.h" #include "tree.h" #include "java-tree.h" -#include "hashtab.h" +#include "hash-table.h" #include <dirent.h> #include "zlib.h" @@ -271,20 +271,34 @@ find_classfile (char *filename, JCF *jcf, const char *dep_name) return open_class (filename, jcf, fd, dep_name); } -/* Returns 1 if the CLASSNAME (really a char *) matches the name - stored in TABLE_ENTRY (also a char *). */ -static int -memoized_class_lookup_eq (const void *table_entry, const void *classname) +/* Hash table helper. */ + +struct charstar_hash : typed_noop_remove <char> +{ + typedef const char T; + static inline hashval_t hash (const T *candidate); + static inline bool equal (const T *existing, const T *candidate); +}; + +inline hashval_t +charstar_hash::hash (const T *candidate) { - return strcmp ((const char *)classname, (const char *)table_entry) == 0; + return htab_hash_string (candidate); } +inline bool +charstar_hash::equal (const T *existing, const T *candidate) +{ + return strcmp (existing, candidate) == 0; +} + + /* A hash table keeping track of class names that were not found during class lookup. (There is no need to cache the values associated with names that were found; they are saved in IDENTIFIER_CLASS_VALUE.) */ -static htab_t memoized_class_lookups; +static hash_table <charstar_hash> memoized_class_lookups; /* Returns a freshly malloc'd string with the fully qualified pathname of the .class file for the class CLASSNAME. CLASSNAME must be @@ -306,16 +320,13 @@ find_class (const char *classname, int classname_length, JCF *jcf) hashval_t hash; /* Create the hash table, if it does not already exist. */ - if (!memoized_class_lookups) - memoized_class_lookups = htab_create (37, - htab_hash_string, - memoized_class_lookup_eq, - NULL); + if (!memoized_class_lookups.is_created ()) + memoized_class_lookups.create (37); /* Loop for this class in the hashtable. If it is present, we've already looked for this class and failed to find it. */ - hash = htab_hash_string (classname); - if (htab_find_with_hash (memoized_class_lookups, classname, hash)) + hash = charstar_hash::hash (classname); + if (memoized_class_lookups.find_with_hash (classname, hash)) return NULL; /* Allocate and zero out the buffer, since we don't explicitly put a @@ -390,8 +401,8 @@ find_class (const char *classname, int classname_length, JCF *jcf) /* Remember that this class could not be found so that we do not have to look again. */ - *htab_find_slot_with_hash (memoized_class_lookups, classname, hash, INSERT) - = (void *) CONST_CAST (char *, classname); + *memoized_class_lookups.find_slot_with_hash (classname, hash, INSERT) + = classname; return NULL; found: |