public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] libiberty: add htab_eq_string
@ 2021-05-07 10:51 Richard Earnshaw
  0 siblings, 0 replies; only message in thread
From: Richard Earnshaw @ 2021-05-07 10:51 UTC (permalink / raw)
  To: bfd-cvs, gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c759c777c98fab555d28d133ef0793607f8c3afc

commit c759c777c98fab555d28d133ef0793607f8c3afc
Author: Tom Tromey <tom@tromey.com>
Date:   Wed Apr 28 18:44:48 2021 -0600

    libiberty: add htab_eq_string
    
    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.

Diff:
---
 include/hashtab.h   | 3 +++
 libiberty/hashtab.c | 7 +++++++
 2 files changed, 10 insertions(+)

diff --git a/include/hashtab.h b/include/hashtab.h
index b3a6265eeb6..77c5eec7905 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 0c7208effe1..7c424e8f6cc 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.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-07 10:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-07 10:51 [binutils-gdb] libiberty: add htab_eq_string Richard Earnshaw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).