From 36e06f2ce3f2789bf51dc156820cdf85dc859b55 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Tue, 10 Jan 2023 15:34:15 -0800 Subject: 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. --- src/til_tap.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') 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 +#include + +#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)), }; } -- cgit v1.2.1