]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libiberty: add htab_eq_string
authorTom Tromey <tom@tromey.com>
Thu, 29 Apr 2021 00:44:48 +0000 (18:44 -0600)
committerTom Tromey <tom@tromey.com>
Thu, 6 May 2021 14:51:28 +0000 (08:51 -0600)
The libiberty hash table includes a helper function for strings, but
no equality function.  Consequently, this equality function has been
reimplemented a number of times in both the gcc and binutils-gdb
source trees.  This patch adds the function to the libiberty hash
table, as a step toward the goal of removing all the copies.

One change to gcc is included here.  Normally I would have put this in
the next patch, but gensupport.c used the most natural name for its
reimplementation of this function, and this can't coexist with the
extern function in libiberty.

include

* hashtab.h (htab_eq_string): Declare.

libiberty

* hashtab.c (htab_eq_string): New function.

gcc

* gensupport.c (htab_eq_string): Remove.

gcc/gensupport.c
include/hashtab.h
libiberty/hashtab.c

index 0f19bd7066466b3ccdf06d0cacb40ead55cb8a9c..e1ca06dbc1ec1463c990ec28da407eb8fa07529c 100644 (file)
@@ -2322,14 +2322,6 @@ gen_reader::handle_unknown_directive (file_location loc, const char *rtx_name)
     process_rtx (x, loc);
 }
 
-/* Comparison function for the mnemonic hash table.  */
-
-static int
-htab_eq_string (const void *s1, const void *s2)
-{
-  return strcmp ((const char*)s1, (const char*)s2) == 0;
-}
-
 /* Add mnemonic STR with length LEN to the mnemonic hash table
    MNEMONIC_HTAB.  A trailing zero end character is appended to STR
    and a permanent heap copy of STR is created.  */
index b3a6265eeb6e03cb10ac1907204e5783f71c66da..77c5eec7905515e1da6dce423d41d9b6cf37b525 100644 (file)
@@ -192,6 +192,9 @@ extern htab_eq htab_eq_pointer;
 /* A hash function for null-terminated strings.  */
 extern hashval_t htab_hash_string (const void *);
 
+/* An equality function for null-terminated strings.  */
+extern int htab_eq_string (const void *, const void *);
+
 /* An iterative hash function for arbitrary data.  */
 extern hashval_t iterative_hash (const void *, size_t, hashval_t);
 /* Shorthand for hashing something with an intrinsic size.  */
index 0c7208effe113020162a9b9e85147df20059b524..7c424e8f6cc1f11c62560d6db5a38dead4e266ea 100644 (file)
@@ -841,6 +841,13 @@ htab_hash_string (const PTR p)
   return r;
 }
 
+/* An equality function for null-terminated strings.  */
+int
+htab_eq_string (const void *a, const void *b)
+{
+  return strcmp ((const char *) a, (const char *) b) == 0;
+}
+
 /* DERIVED FROM:
 --------------------------------------------------------------------
 lookup2.c, by Bob Jenkins, December 1996, Public Domain.