From: Tom Tromey <tom@tromey.com>
To: John Baldwin <jhb@FreeBSD.org>
Cc: Tom Tromey <tom@tromey.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 2/9] Introduce and use language_set
Date: Fri, 08 Mar 2019 22:43:00 -0000 [thread overview]
Message-ID: <87bm2ldm20.fsf@tromey.com> (raw)
In-Reply-To: <6387c828-db23-3e49-fb76-699f5fc9e82b@FreeBSD.org> (John Baldwin's message of "Thu, 7 Mar 2019 15:04:38 -0800")
John> Hmm, did you consider using std::bitset<nr_languages> for langauge_set? You'd
John> still have to write your own iterator class, so it wouldn't save much in terms
John> of lines of code.
In this case, because there are just two spots that iterate over this
set, and because we'd need to introduce somewhat ugly casts back to
"enum language" anyway, it seemed just as good to not write an iterator
and just do this in a simpler way.
Tom
commit d52ac096d7ae33144eb3a691a78e061d32833444
Author: Tom Tromey <tom@tromey.com>
Date: Fri Mar 1 19:55:46 2019 -0700
Use bitset for demangled_hash_languages
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 bitset. This patch
reimplements it as a std::bitset.
gdb/ChangeLog
2019-03-08 Tom Tromey <tom@tromey.com>
* objfiles.h (struct objfile_per_bfd_storage)
<demangled_hash_languages>: Now a bitset.
* minsyms.c (add_minsym_to_demangled_hash_table): Update.
(lookup_minimal_symbol): Update.
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7ec81d36571..4c952b0a445 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2019-03-08 Tom Tromey <tom@tromey.com>
+
+ * objfiles.h (struct objfile_per_bfd_storage)
+ <demangled_hash_languages>: Now a bitset.
+ * minsyms.c (add_minsym_to_demangled_hash_table): Update.
+ (lookup_minimal_symbol): Update.
+
2019-03-07 Tom Tromey <tom@tromey.com>
* minsyms.h (class minimal_symbol_reader) <record_with_info>:
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index 0513cfe69f4..cbb45f141c9 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -160,11 +160,7 @@ 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.set (MSYMBOL_LANGUAGE (sym));
struct minimal_symbol **table
= objfile->per_bfd->msymbol_demangled_hash;
@@ -354,8 +350,12 @@ lookup_minimal_symbol (const char *name, const char *sfile,
{
/* Once for each language in the demangled hash names
table (usually just zero or one languages). */
- for (auto lang : objfile->per_bfd->demangled_hash_languages)
+ for (unsigned iter = 0; iter < nr_languages; ++iter)
{
+ if (!objfile->per_bfd->demangled_hash_languages.test (iter))
+ continue;
+ enum language lang = (enum language) iter;
+
unsigned int hash
= (lookup_name.search_name_hash (lang)
% MINIMAL_SYMBOL_HASH_SIZE);
@@ -497,8 +497,12 @@ iterate_over_minimal_symbols
/* The second pass is over the demangled table. Once for each
language in the demangled hash names table (usually just zero or
one). */
- for (auto lang : objf->per_bfd->demangled_hash_languages)
+ for (unsigned liter = 0; liter < nr_languages; ++liter)
{
+ if (!objf->per_bfd->demangled_hash_languages.test (liter))
+ continue;
+
+ enum language lang = (enum language) liter;
const language_defn *lang_def = language_def (lang);
symbol_name_matcher_ftype *name_match
= get_symbol_name_matcher (lang_def, lookup_name);
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index c5ce9eec955..47df0023dcc 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -28,6 +28,7 @@
#include "registry.h"
#include "gdb_bfd.h"
#include "psymtab.h"
+#include <bitset>
#include <vector>
#include "common/next-iterator.h"
#include "common/safe-iterator.h"
@@ -313,10 +314,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. */
+ std::bitset<nr_languages> demangled_hash_languages;
};
/* Master structure for keeping track of each file from which
next prev parent reply other threads:[~2019-03-08 22:43 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 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-07 20:57 ` [PATCH 5/9] Simplify per-BFD storage management Tom Tromey
2019-03-07 20:57 ` [PATCH 6/9] Use htab_up for demangled hash 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 2/9] Introduce and use language_set Tom Tromey
2019-03-07 23:05 ` John Baldwin
2019-03-08 22:21 ` Tom Tromey
2019-03-08 22:43 ` Tom Tromey [this message]
2019-03-08 23:44 ` John Baldwin
2019-03-07 20:57 ` [PATCH 3/9] Remove some unneeded initializations in minimal_symbol_reader Tom Tromey
2019-03-07 20:57 ` [PATCH 4/9] Remove minsym termination 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=87bm2ldm20.fsf@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
--cc=jhb@FreeBSD.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