summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-01-10 15:34:15 -0800
committerVito Caputo <vcaputo@pengaru.com>2023-01-10 23:51:44 -0800
commit36e06f2ce3f2789bf51dc156820cdf85dc859b55 (patch)
treedf2dde03b479ff2aa8c2977392367d091d9bd1cc
parentb384a96e4a0692d8ed01d4ddf34ccba204e3d7f6 (diff)
til_tap: hash tap name
The purpose of the tap is ultimately to be indexed by name so it's discoverable. I'm leaning towards using a hash table for that, and it'd be silly to keep recomputing the hash of an unchanging name.
-rw-r--r--src/til_tap.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/til_tap.h b/src/til_tap.h
index 62e3c37..64eeaf0 100644
--- a/src/til_tap.h
+++ b/src/til_tap.h
@@ -2,6 +2,9 @@
#define _TIL_TAP_H
#include <stdint.h>
+#include <string.h>
+
+#include "til_jenkins.h"
/* A "tap" is a named binding of a local variable+pointer to that variable.
*
@@ -45,10 +48,11 @@ typedef enum til_tap_type_t {
/* this is deliberately left entirely public so taps can be easily embedded in contexts */
typedef struct til_tap_t {
til_tap_type_t type;
- void *ptr; /* points at the caller-provided tap-managed indirection pointer */
+ void **ptr; /* points at the caller-provided tap-managed indirection pointer */
size_t n_elems; /* when > 1, *ptr is an array of n_elems elements. Otherwise individual variable. */
void *elems; /* points at the first element of type type, may or may not be an array of them */
const char *name;
+ uint32_t name_hash; /* cached hash of name, set once @ initialization */
} til_tap_t;
/* just some forward declared higher-order vector and matrix types for the wrappers */
@@ -74,6 +78,7 @@ static inline til_tap_t til_tap_init(til_tap_type_t type, void *ptr, size_t n_el
.n_elems = n_elems,
.elems = elems,
.name = name,
+ .name_hash = til_jenkins((uint8_t *)name, strlen(name)),
};
}
© All Rights Reserved