[v2,3/4] Move hash_entry and eq_entry into cooked_index::do_finalize

Message ID 20230110183338.2623088-4-tromey@adacore.com
State Committed
Headers
Series Fix regression in new DWARF reader |

Commit Message

Tom Tromey Jan. 10, 2023, 6:33 p.m. UTC
  I was briefly confused by the hash_entry and eq_entry functions in the
cooked index.  They are only needed in a single method, and that
method already has a couple of local lambdas for a different hash
table.  So, it seemed cleaner to move these there as well.
---
 gdb/dwarf2/cooked-index.c | 34 ++++++++++++++--------------------
 1 file changed, 14 insertions(+), 20 deletions(-)
  

Comments

Joel Brobecker Jan. 14, 2023, 6:06 a.m. UTC | #1
> I was briefly confused by the hash_entry and eq_entry functions in the
> cooked index.  They are only needed in a single method, and that
> method already has a couple of local lambdas for a different hash
> table.  So, it seemed cleaner to move these there as well.

Still OK for me :-).

>  gdb/dwarf2/cooked-index.c | 34 ++++++++++++++--------------------
>  1 file changed, 14 insertions(+), 20 deletions(-)
> 
> diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c
> index 93ffd923c76..c711e3b9b2a 100644
> --- a/gdb/dwarf2/cooked-index.c
> +++ b/gdb/dwarf2/cooked-index.c
> @@ -26,26 +26,6 @@
>  #include "split-name.h"
>  #include <algorithm>
>  
> -/* Hash function for cooked_index_entry.  */
> -
> -static hashval_t
> -hash_entry (const void *e)
> -{
> -  const cooked_index_entry *entry = (const cooked_index_entry *) e;
> -  return dwarf5_djb_hash (entry->canonical);
> -}
> -
> -/* Equality function for cooked_index_entry.  */
> -
> -static int
> -eq_entry (const void *a, const void *b)
> -{
> -  const cooked_index_entry *ae = (const cooked_index_entry *) a;
> -  const gdb::string_view *sv = (const gdb::string_view *) b;
> -  return (strlen (ae->canonical) == sv->length ()
> -	  && strncasecmp (ae->canonical, sv->data (), sv->length ()) == 0);
> -}
> -
>  /* See cooked-index.h.  */
>  
>  const char *
> @@ -191,6 +171,20 @@ cooked_index::do_finalize ()
>    htab_up seen_names (htab_create_alloc (10, hash_name_ptr, eq_name_ptr,
>  					 nullptr, xcalloc, xfree));
>  
> +  auto hash_entry = [] (const void *e)
> +    {
> +      const cooked_index_entry *entry = (const cooked_index_entry *) e;
> +      return dwarf5_djb_hash (entry->canonical);
> +    };
> +
> +  auto eq_entry = [] (const void *a, const void *b) -> int
> +    {
> +      const cooked_index_entry *ae = (const cooked_index_entry *) a;
> +      const gdb::string_view *sv = (const gdb::string_view *) b;
> +      return (strlen (ae->canonical) == sv->length ()
> +	      && strncasecmp (ae->canonical, sv->data (), sv->length ()) == 0);
> +    };
> +
>    htab_up gnat_entries (htab_create_alloc (10, hash_entry, eq_entry,
>  					   nullptr, xcalloc, xfree));
>  
> -- 
> 2.38.1
>
  

Patch

diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c
index 93ffd923c76..c711e3b9b2a 100644
--- a/gdb/dwarf2/cooked-index.c
+++ b/gdb/dwarf2/cooked-index.c
@@ -26,26 +26,6 @@ 
 #include "split-name.h"
 #include <algorithm>
 
-/* Hash function for cooked_index_entry.  */
-
-static hashval_t
-hash_entry (const void *e)
-{
-  const cooked_index_entry *entry = (const cooked_index_entry *) e;
-  return dwarf5_djb_hash (entry->canonical);
-}
-
-/* Equality function for cooked_index_entry.  */
-
-static int
-eq_entry (const void *a, const void *b)
-{
-  const cooked_index_entry *ae = (const cooked_index_entry *) a;
-  const gdb::string_view *sv = (const gdb::string_view *) b;
-  return (strlen (ae->canonical) == sv->length ()
-	  && strncasecmp (ae->canonical, sv->data (), sv->length ()) == 0);
-}
-
 /* See cooked-index.h.  */
 
 const char *
@@ -191,6 +171,20 @@  cooked_index::do_finalize ()
   htab_up seen_names (htab_create_alloc (10, hash_name_ptr, eq_name_ptr,
 					 nullptr, xcalloc, xfree));
 
+  auto hash_entry = [] (const void *e)
+    {
+      const cooked_index_entry *entry = (const cooked_index_entry *) e;
+      return dwarf5_djb_hash (entry->canonical);
+    };
+
+  auto eq_entry = [] (const void *a, const void *b) -> int
+    {
+      const cooked_index_entry *ae = (const cooked_index_entry *) a;
+      const gdb::string_view *sv = (const gdb::string_view *) b;
+      return (strlen (ae->canonical) == sv->length ()
+	      && strncasecmp (ae->canonical, sv->data (), sv->length ()) == 0);
+    };
+
   htab_up gnat_entries (htab_create_alloc (10, hash_entry, eq_entry,
 					   nullptr, xcalloc, xfree));