diff options
author | Nick Alcock <nick.alcock@oracle.com> | 2020-06-02 22:26:38 +0100 |
---|---|---|
committer | Nick Alcock <nick.alcock@oracle.com> | 2020-07-22 17:57:45 +0100 |
commit | 77648241384a5c46f059efeb157a2887116d844a (patch) | |
tree | 469c5085a14fb2c9151c127ec0fbc36e80afbdc1 /libctf/ctf-impl.h | |
parent | a49c6c6a656c429dc222e04628e085a903194b51 (diff) | |
download | gdb-77648241384a5c46f059efeb157a2887116d844a.zip gdb-77648241384a5c46f059efeb157a2887116d844a.tar.gz gdb-77648241384a5c46f059efeb157a2887116d844a.tar.bz2 |
libctf, hash: introduce the ctf_dynset
There are many places in the deduplicator which use hashtables as tiny
sets: keys with no value (and usually, but not always, no freeing
function) often with only one or a few members. For each of these, even
after the last change to not store the freeing functions, we are storing
a little malloced block for each item just to track the key/value pair,
and a little malloced block for the hash table itself just to track the
freeing function because we can't use libiberty hashtab's freeing
function because we are using that to free the little malloced per-item
block.
If we only have a key, we don't need any of that: we can ditch the
per-malloced block because we don't have a value, and we can ditch the
per-hashtab structure because we don't need to independently track the
freeing functions since libiberty hashtab is doing it for us. That
means we don't need an owner field in the (now nonexistent) item block
either.
Roughly speaking, this datatype saves about 25% in time and 20% in peak
memory usage for normal links, even fairly big ones. So this might seem
redundant, but it's really worth it.
Instead of a _lookup function, a dynset has two distinct functions:
ctf_dynset_exists, which returns true or false and an optional pointer
to the set member, and ctf_dynhash_lookup_any, which is used if all
members of the set are expected to be equivalent and we just want *any*
member and we don't care which one.
There is no iterator in this set of functions, not because we don't
iterate over dynset members -- we do, a lot -- but because the iterator
here is a member of an entirely new family of much more convenient
iteration functions, introduced in the next commit.
libctf/
* ctf-hash.c (ctf_dynset_eq_string): New.
(ctf_dynset_create): New.
(DYNSET_EMPTY_ENTRY_REPLACEMENT): New.
(DYNSET_DELETED_ENTRY_REPLACEMENT): New.
(key_to_internal): New.
(internal_to_key): New.
(ctf_dynset_insert): New.
(ctf_dynset_remove): New.
(ctf_dynset_destroy): New.
(ctf_dynset_lookup): New.
(ctf_dynset_exists): New.
(ctf_dynset_lookup_any): New.
(ctf_hash_insert_type): Coding style.
(ctf_hash_define_type): Likewise.
* ctf-impl.h (ctf_dynset_t): New.
(ctf_dynset_eq_string): New.
(ctf_dynset_create): New.
(ctf_dynset_insert): New.
(ctf_dynset_remove): New.
(ctf_dynset_destroy): New.
(ctf_dynset_lookup): New.
(ctf_dynset_exists): New.
(ctf_dynset_lookup_any): New.
* ctf-inlines.h (ctf_dynset_cinsert): New.
Diffstat (limited to 'libctf/ctf-impl.h')
-rw-r--r-- | libctf/ctf-impl.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/libctf/ctf-impl.h b/libctf/ctf-impl.h index 3e09779..7d583ab 100644 --- a/libctf/ctf-impl.h +++ b/libctf/ctf-impl.h @@ -34,6 +34,7 @@ #include <ctype.h> #include <elf.h> #include <bfd.h> +#include "hashtab.h" #ifdef __cplusplus extern "C" @@ -73,6 +74,7 @@ extern "C" typedef struct ctf_fixed_hash ctf_hash_t; /* Private to ctf-hash.c. */ typedef struct ctf_dynhash ctf_dynhash_t; /* Private to ctf-hash.c. */ +typedef struct ctf_dynset ctf_dynset_t; /* Private to ctf-hash.c. */ typedef struct ctf_strs { @@ -378,6 +380,8 @@ extern int ctf_hash_eq_integer (const void *, const void *); extern int ctf_hash_eq_string (const void *, const void *); extern int ctf_hash_eq_type_mapping_key (const void *, const void *); +extern int ctf_dynset_eq_string (const void *, const void *); + typedef void (*ctf_hash_free_fun) (void *); typedef void (*ctf_hash_iter_f) (void *key, void *value, void *arg); @@ -407,6 +411,15 @@ extern void ctf_dynhash_iter_remove (ctf_dynhash_t *, ctf_hash_iter_remove_f, extern void *ctf_dynhash_iter_find (ctf_dynhash_t *, ctf_hash_iter_find_f, void *); +extern ctf_dynset_t *ctf_dynset_create (htab_hash, htab_eq, ctf_hash_free_fun); +extern int ctf_dynset_insert (ctf_dynset_t *, void *); +extern void ctf_dynset_remove (ctf_dynset_t *, const void *); +extern void ctf_dynset_destroy (ctf_dynset_t *); +extern void *ctf_dynset_lookup (ctf_dynset_t *, const void *); +extern int ctf_dynset_exists (ctf_dynset_t *, const void *key, + const void **orig_key); +extern void *ctf_dynset_lookup_any (ctf_dynset_t *); + #define ctf_list_prev(elem) ((void *)(((ctf_list_t *)(elem))->l_prev)) #define ctf_list_next(elem) ((void *)(((ctf_list_t *)(elem))->l_next)) |