Message ID | 20210505213317.513520-2-tom@tromey.com |
---|---|
State | New |
Headers | show |
Series | Add htab_eq_string to libiberty | expand |
On Thu, May 6, 2021 at 12:41 AM Tom Tromey <tom@tromey.com> wrote: > > 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. OK. > 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 | 8 -------- > include/hashtab.h | 3 +++ > libiberty/hashtab.c | 7 +++++++ > 3 files changed, 10 insertions(+), 8 deletions(-) > > diff --git a/gcc/gensupport.c b/gcc/gensupport.c > index 0f19bd706646..e1ca06dbc1ec 100644 > --- a/gcc/gensupport.c > +++ b/gcc/gensupport.c > @@ -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. */ > diff --git a/include/hashtab.h b/include/hashtab.h > index b3a6265eeb6e..77c5eec79055 100644 > --- a/include/hashtab.h > +++ b/include/hashtab.h > @@ -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. */ > diff --git a/libiberty/hashtab.c b/libiberty/hashtab.c > index 0c7208effe11..7c424e8f6cc1 100644 > --- a/libiberty/hashtab.c > +++ b/libiberty/hashtab.c > @@ -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. > -- > 2.26.3 >
diff --git a/gcc/gensupport.c b/gcc/gensupport.c index 0f19bd706646..e1ca06dbc1ec 100644 --- a/gcc/gensupport.c +++ b/gcc/gensupport.c @@ -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. */ diff --git a/include/hashtab.h b/include/hashtab.h index b3a6265eeb6e..77c5eec79055 100644 --- a/include/hashtab.h +++ b/include/hashtab.h @@ -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. */ diff --git a/libiberty/hashtab.c b/libiberty/hashtab.c index 0c7208effe11..7c424e8f6cc1 100644 --- a/libiberty/hashtab.c +++ b/libiberty/hashtab.c @@ -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.