Use htab_up in completion_tracker

This changes completion_tracker to use htab_up, rather than explicit
calls to htab_delete.

gdb/ChangeLog
2020-09-17  Tom Tromey  <tom@tromey.com>

	* completer.c (completion_tracker::discard_completions)
	(completion_tracker::~completion_tracker)
	(completion_tracker::maybe_add_completion)
	(completion_tracker::remove_completion)
	(completion_tracker::recompute_lowest_common_denominator)
	(completion_tracker::build_completion_result): Update.
	* completer.h (class completion_tracker) <have_completions>:
	Update.
	<m_entries_hash>: Now htab_up.
This commit is contained in:
Tom Tromey 2020-09-17 11:47:50 -06:00
parent c1fb98360c
commit 32580f6d2e
3 changed files with 27 additions and 18 deletions

View File

@ -1,3 +1,15 @@
2020-09-17 Tom Tromey <tom@tromey.com>
* completer.c (completion_tracker::discard_completions)
(completion_tracker::~completion_tracker)
(completion_tracker::maybe_add_completion)
(completion_tracker::remove_completion)
(completion_tracker::recompute_lowest_common_denominator)
(completion_tracker::build_completion_result): Update.
* completer.h (class completion_tracker) <have_completions>:
Update.
<m_entries_hash>: Now htab_up.
2020-09-17 Tom Tromey <tom@tromey.com> 2020-09-17 Tom Tromey <tom@tromey.com>
* breakpoint.c (ambiguous_names_p): Use htab_up. * breakpoint.c (ambiguous_names_p): Use htab_up.

View File

@ -1587,10 +1587,7 @@ completion_tracker::discard_completions ()
m_lowest_common_denominator_unique = false; m_lowest_common_denominator_unique = false;
m_lowest_common_denominator_valid = false; m_lowest_common_denominator_valid = false;
/* A null check here allows this function to be used from the m_entries_hash.reset (nullptr);
constructor. */
if (m_entries_hash != NULL)
htab_delete (m_entries_hash);
/* A callback used by the hash table to compare new entries with existing /* A callback used by the hash table to compare new entries with existing
entries. We can't use the standard streq_hash function here as the entries. We can't use the standard streq_hash function here as the
@ -1618,10 +1615,10 @@ completion_tracker::discard_completions ()
return entry->hash_name (); return entry->hash_name ();
}; };
m_entries_hash = htab_create_alloc (INITIAL_COMPLETION_HTAB_SIZE, m_entries_hash.reset (htab_create_alloc (INITIAL_COMPLETION_HTAB_SIZE,
entry_hash_func, entry_eq_func, entry_hash_func, entry_eq_func,
completion_hash_entry::deleter, completion_hash_entry::deleter,
xcalloc, xfree); xcalloc, xfree));
} }
/* See completer.h. */ /* See completer.h. */
@ -1629,7 +1626,6 @@ completion_tracker::discard_completions ()
completion_tracker::~completion_tracker () completion_tracker::~completion_tracker ()
{ {
xfree (m_lowest_common_denominator); xfree (m_lowest_common_denominator);
htab_delete (m_entries_hash);
} }
/* See completer.h. */ /* See completer.h. */
@ -1645,11 +1641,12 @@ completion_tracker::maybe_add_completion
if (max_completions == 0) if (max_completions == 0)
return false; return false;
if (htab_elements (m_entries_hash) >= max_completions) if (htab_elements (m_entries_hash.get ()) >= max_completions)
return false; return false;
hashval_t hash = htab_hash_string (name.get ()); hashval_t hash = htab_hash_string (name.get ());
slot = htab_find_slot_with_hash (m_entries_hash, name.get (), hash, INSERT); slot = htab_find_slot_with_hash (m_entries_hash.get (), name.get (),
hash, INSERT);
if (*slot == HTAB_EMPTY_ENTRY) if (*slot == HTAB_EMPTY_ENTRY)
{ {
const char *match_for_lcd_str = NULL; const char *match_for_lcd_str = NULL;
@ -1700,10 +1697,10 @@ void
completion_tracker::remove_completion (const char *name) completion_tracker::remove_completion (const char *name)
{ {
hashval_t hash = htab_hash_string (name); hashval_t hash = htab_hash_string (name);
if (htab_find_slot_with_hash (m_entries_hash, name, hash, NO_INSERT) if (htab_find_slot_with_hash (m_entries_hash.get (), name, hash, NO_INSERT)
!= NULL) != NULL)
{ {
htab_remove_elt_with_hash (m_entries_hash, name, hash); htab_remove_elt_with_hash (m_entries_hash.get (), name, hash);
m_lowest_common_denominator_valid = false; m_lowest_common_denominator_valid = false;
} }
} }
@ -2144,7 +2141,7 @@ completion_tracker::recompute_lowest_common_denominator ()
return 1; return 1;
}; };
htab_traverse (m_entries_hash, visitor_func, this); htab_traverse (m_entries_hash.get (), visitor_func, this);
m_lowest_common_denominator_valid = true; m_lowest_common_denominator_valid = true;
} }
@ -2227,7 +2224,7 @@ completion_result
completion_tracker::build_completion_result (const char *text, completion_tracker::build_completion_result (const char *text,
int start, int end) int start, int end)
{ {
size_t element_count = htab_elements (m_entries_hash); size_t element_count = htab_elements (m_entries_hash.get ());
if (element_count == 0) if (element_count == 0)
return {}; return {};
@ -2294,7 +2291,7 @@ completion_tracker::build_completion_result (const char *text,
}; };
/* Build the completion list and add a null at the end. */ /* Build the completion list and add a null at the end. */
htab_traverse_noresize (m_entries_hash, func, &builder); htab_traverse_noresize (m_entries_hash.get (), func, &builder);
match_list[builder.index] = NULL; match_list[builder.index] = NULL;
return completion_result (match_list, builder.index - 1, false); return completion_result (match_list, builder.index - 1, false);

View File

@ -393,7 +393,7 @@ public:
/* True if we have any completion match recorded. */ /* True if we have any completion match recorded. */
bool have_completions () const bool have_completions () const
{ return htab_elements (m_entries_hash) > 0; } { return htab_elements (m_entries_hash.get ()) > 0; }
/* Discard the current completion match list and the current /* Discard the current completion match list and the current
LCD. */ LCD. */
@ -440,7 +440,7 @@ private:
will remove duplicates, and if removal of duplicates there brings will remove duplicates, and if removal of duplicates there brings
the total under max_completions the user may think gdb quit the total under max_completions the user may think gdb quit
searching too early. */ searching too early. */
htab_t m_entries_hash = NULL; htab_up m_entries_hash;
/* If non-zero, then this is the quote char that needs to be /* If non-zero, then this is the quote char that needs to be
appended after completion (iff we have a unique completion). We appended after completion (iff we have a unique completion). We