aboutsummaryrefslogtreecommitdiff
path: root/libctf/ctf-inlines.h
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2020-06-02 22:26:38 +0100
committerNick Alcock <nick.alcock@oracle.com>2020-07-22 17:57:45 +0100
commit77648241384a5c46f059efeb157a2887116d844a (patch)
tree469c5085a14fb2c9151c127ec0fbc36e80afbdc1 /libctf/ctf-inlines.h
parenta49c6c6a656c429dc222e04628e085a903194b51 (diff)
downloadgdb-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-inlines.h')
-rw-r--r--libctf/ctf-inlines.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/libctf/ctf-inlines.h b/libctf/ctf-inlines.h
index ad74b39..f9c1b2a 100644
--- a/libctf/ctf-inlines.h
+++ b/libctf/ctf-inlines.h
@@ -38,6 +38,12 @@ ctf_dynhash_cinsert (ctf_dynhash_t *h, const void *k, const void *v)
return ctf_dynhash_insert (h, (void *) k, (void *) v);
}
+static inline int
+ctf_dynset_cinsert (ctf_dynset_t *h, const void *k)
+{
+ return ctf_dynset_insert (h, (void *) k);
+}
+
#ifdef __cplusplus
}
#endif