From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 2/9] Introduce and use language_set
Date: Thu, 07 Mar 2019 20:57:00 -0000 [thread overview]
Message-ID: <20190307205709.21919-3-tom@tromey.com> (raw)
In-Reply-To: <20190307205709.21919-1-tom@tromey.com>
I noticed that objfile_per_bfd_storage::demangled_hash_languages is a
std::vector, which seemed quite large for something that,
fundamentally, can be represented as a bit-set. This patch
reimplements it as a bit-set.
gdb/ChangeLog
2019-03-07 Tom Tromey <tom@tromey.com>
* objfiles.h (struct objfile_per_bfd_storage)
<demangled_hash_languages>: Now a language_set.
* minsyms.c (add_minsym_to_demangled_hash_table): Update.
* language.h (class language_set): New.
---
gdb/ChangeLog | 7 +++++
gdb/language.h | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++
gdb/minsyms.c | 7 ++---
gdb/objfiles.h | 6 ++--
4 files changed, 95 insertions(+), 9 deletions(-)
diff --git a/gdb/language.h b/gdb/language.h
index d56ec200208..d57eee96a12 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -747,4 +747,88 @@ private:
enum language m_lang;
};
+/* A set object specialized for keeping track of languages. */
+
+class language_set
+{
+public:
+
+ language_set ()
+ {
+ }
+
+ /* Insert LANG into this set. */
+ void insert (enum language lang)
+ {
+ m_mask |= 1 << lang;
+ }
+
+ /* The underlying type used to represent the languages. */
+ typedef unsigned mask_type;
+
+ /* An iterator that iterates over languages contained in a language
+ set. */
+ class iterator
+ {
+ public:
+
+ iterator (unsigned int n, mask_type mask)
+ : m_index (n),
+ m_mask (mask)
+ {
+ gdb_assert (m_index <= nr_languages);
+ update ();
+ }
+
+ enum language operator* () const
+ {
+ return (enum language) m_index;
+ }
+
+ iterator &operator++ ()
+ {
+ ++m_index;
+ update ();
+ return *this;
+ }
+
+ bool operator!= (const iterator &other) const
+ {
+ return m_index != other.m_index;
+ }
+
+ private:
+
+ /* A helper function that will advance M_INDEX to the next
+ language in the set. */
+ void update ()
+ {
+ while (m_index < nr_languages && (m_mask & (1 << m_index)) == 0)
+ ++m_index;
+ }
+
+ /* The current index of the iterator. */
+ unsigned int m_index;
+ /* The mask from the underlying set. */
+ mask_type m_mask;
+ };
+
+ iterator begin () const
+ {
+ return iterator (0, m_mask);
+ }
+
+ iterator end () const
+ {
+ return iterator (nr_languages, m_mask);
+ }
+
+private:
+
+ /* A bit mask of languages which are included in this set. */
+ mask_type m_mask = 0;
+
+ gdb_static_assert (nr_languages <= (sizeof (mask_type) * CHAR_BIT));
+};
+
#endif /* defined (LANGUAGE_H) */
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index 0513cfe69f4..6395cc4ccab 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -160,11 +160,8 @@ add_minsym_to_demangled_hash_table (struct minimal_symbol *sym,
unsigned int hash = search_name_hash (MSYMBOL_LANGUAGE (sym),
MSYMBOL_SEARCH_NAME (sym));
- auto &vec = objfile->per_bfd->demangled_hash_languages;
- auto it = std::lower_bound (vec.begin (), vec.end (),
- MSYMBOL_LANGUAGE (sym));
- if (it == vec.end () || *it != MSYMBOL_LANGUAGE (sym))
- vec.insert (it, MSYMBOL_LANGUAGE (sym));
+ objfile->per_bfd->demangled_hash_languages.insert
+ (MSYMBOL_LANGUAGE (sym));
struct minimal_symbol **table
= objfile->per_bfd->msymbol_demangled_hash;
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index c5ce9eec955..843c44e1d24 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -313,10 +313,8 @@ struct objfile_per_bfd_storage
minimal_symbol *msymbol_demangled_hash[MINIMAL_SYMBOL_HASH_SIZE] {};
/* All the different languages of symbols found in the demangled
- hash table. A flat/vector-based map is more efficient than a map
- or hash table here, since this will only usually contain zero or
- one entries. */
- std::vector<enum language> demangled_hash_languages;
+ hash table. */
+ language_set demangled_hash_languages;
};
/* Master structure for keeping track of each file from which
--
2.17.2
next prev parent reply other threads:[~2019-03-07 20:57 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-07 21:11 [PATCH 0/9] Minor minimal symbol improvements Tom Tromey
2019-03-07 20:57 ` [PATCH 3/9] Remove some unneeded initializations in minimal_symbol_reader Tom Tromey
2019-03-07 20:57 ` Tom Tromey [this message]
2019-03-07 23:05 ` [PATCH 2/9] Introduce and use language_set John Baldwin
2019-03-08 22:21 ` Tom Tromey
2019-03-08 22:43 ` Tom Tromey
2019-03-08 23:44 ` John Baldwin
2019-03-07 20:57 ` [PATCH 4/9] Remove minsym termination Tom Tromey
2019-03-07 20:57 ` [PATCH 8/9] Use memcpy in minimal_symbol_reader::install Tom Tromey
2019-03-07 20:57 ` [PATCH 6/9] Use htab_up for demangled hash Tom Tromey
2019-03-07 20:57 ` [PATCH 5/9] Simplify per-BFD storage management Tom Tromey
2019-03-07 20:57 ` [PATCH 9/9] Change minimal_symbol inheritance Tom Tromey
2019-03-07 20:57 ` [PATCH 7/9] Allocate minimal symbols with malloc Tom Tromey
2019-03-07 20:57 ` [PATCH 1/9] Slightly simplify minsym creation Tom Tromey
2019-03-15 22:04 ` [PATCH 0/9] Minor minimal symbol improvements Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190307205709.21919-3-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox