summaryrefslogtreecommitdiff
path: root/src/trie.h
diff options
context:
space:
mode:
authorEugene Syromyatnikov <evgsyr@gmail.com>2021-08-19 04:00:34 +0200
committerDmitry V. Levin <ldv@strace.io>2021-08-19 02:00:34 +0000
commit59c36e9d14fb35303026168b3620d923725645b0 (patch)
treec2523bcb9b35447632d2480c430ffe9a48108fdf /src/trie.h
parent94ae5c2cad7a081d92974a6608326caabf708ffc (diff)
downloadstrace-59c36e9d14fb35303026168b3620d923725645b0.tar.gz
trie: cache fill_value value instead of calculating it each time
trie_create_data_block may be a rather hot function if a trie is actively used; it seems wasteful to re-calculate fill_value each time a new data block is allocated, considering the fact that it, as well as empty_value, remains constant after the trie creation. Let's prematurely optimise it by pre-calculating the value in trie_create. * src/trie.h (struct trie): Add fill_value field. * src/trie.c (trie_create_data_block): Move fill_value calculation... (trie_create): ...here, assign it to the fill_value field.
Diffstat (limited to 'src/trie.h')
-rw-r--r--src/trie.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/trie.h b/src/trie.h
index 0ec5af226..f82a83aa7 100644
--- a/src/trie.h
+++ b/src/trie.h
@@ -36,6 +36,11 @@
struct trie {
/** Return value of trie_get if key is not found */
uint64_t empty_value;
+ /**
+ * Empty value copied over to fill the whole uint64_t.
+ * Pre-calculated in trie_create to be used in trie_create_data_block.
+ */
+ uint64_t fill_value;
/** Pointer to root node */
void *data;