aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2019-08-05 20:57:15 +0200
committerGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2019-08-05 20:57:15 +0200
commit66f4b6b7495cda05fed904c53dd8d04e35538653 (patch)
tree18630495eb0f6ba6769584c34b0c66acf3339967 /src
parent7347610dfdc57045578cdba7e33806ab1d0e9a8a (diff)
downloadd2tk-66f4b6b7495cda05fed904c53dd8d04e35538653.zip
d2tk-66f4b6b7495cda05fed904c53dd8d04e35538653.tar.gz
d2tk-66f4b6b7495cda05fed904c53dd8d04e35538653.tar.bz2
d2tk-66f4b6b7495cda05fed904c53dd8d04e35538653.tar.xz
base: use d2tk_hash_dict instead of *_foreach.
Diffstat (limited to 'src')
-rw-r--r--src/base.c244
-rw-r--r--src/mum.c13
2 files changed, 149 insertions, 108 deletions
diff --git a/src/base.c b/src/base.c
index b9462a6..496e459 100644
--- a/src/base.c
+++ b/src/base.c
@@ -412,19 +412,29 @@ D2TK_API d2tk_frame_t *
d2tk_frame_begin(d2tk_base_t *base, const d2tk_rect_t *rect,
ssize_t lbl_len, const char *lbl, d2tk_frame_t *frm)
{
+ const bool has_lbl = lbl_len && lbl;
+
const d2tk_style_t *style = d2tk_base_get_style(base);
d2tk_core_t *core = base->core;
const d2tk_coord_t h = 17; //FIXME
+ if(has_lbl && (lbl_len == -1) ) // zero-terminated string
+ {
+ lbl_len = strlen(lbl);
+ }
+
+ const d2tk_hash_dict_t dict [] = {
+ { rect, sizeof(d2tk_rect_t) },
+ { style, sizeof(d2tk_style_t) },
+ { lbl, lbl_len },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
+
d2tk_rect_shrink(&frm->rect, rect, 2*style->padding);
frm->rect.y += h;
frm->rect.h -= h;
- const uint64_t hash = d2tk_hash_foreach(rect, sizeof(d2tk_rect_t),
- style, sizeof(d2tk_style_t),
- lbl, lbl_len,
- NULL);
-
D2TK_CORE_WIDGET(core, hash, widget)
{
d2tk_rect_t bnd_outer;
@@ -435,11 +445,6 @@ d2tk_frame_begin(d2tk_base_t *base, const d2tk_rect_t *rect,
if(lbl)
{
- if(lbl_len == -1) // zero terminated string
- {
- lbl_len = strlen(lbl);
- }
-
bnd_inner.h = h;
d2tk_core_begin_path(core);
@@ -1173,13 +1178,16 @@ _d2tk_draw_scrollbar(d2tk_core_t *core, d2tk_state_t hstate, d2tk_state_t vstate
const d2tk_rect_t *hbar, const d2tk_rect_t *vbar, const d2tk_style_t *style,
d2tk_flag_t flags)
{
- const uint64_t hash = d2tk_hash_foreach(&hstate, sizeof(d2tk_state_t),
- &vstate, sizeof(d2tk_state_t),
- hbar, sizeof(d2tk_rect_t),
- vbar, sizeof(d2tk_rect_t),
- style, sizeof(d2tk_style_t),
- &flags, sizeof(d2tk_flag_t),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { &hstate, sizeof(d2tk_state_t) },
+ { &vstate, sizeof(d2tk_state_t) },
+ { hbar, sizeof(d2tk_rect_t) },
+ { vbar, sizeof(d2tk_rect_t) },
+ { style, sizeof(d2tk_style_t) },
+ { &flags, sizeof(d2tk_flag_t) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
D2TK_CORE_WIDGET(core, hash, widget)
{
@@ -1427,11 +1435,14 @@ static void
_d2tk_draw_pane(d2tk_core_t *core, d2tk_state_t state, const d2tk_rect_t *sub,
const d2tk_style_t *style, d2tk_flag_t flags)
{
- const uint64_t hash = d2tk_hash_foreach(&state, sizeof(d2tk_state_t),
- sub, sizeof(d2tk_rect_t),
- style, sizeof(d2tk_style_t),
- &flags, sizeof(d2tk_flag_t),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { &state, sizeof(d2tk_state_t) },
+ { sub, sizeof(d2tk_rect_t) },
+ { style, sizeof(d2tk_style_t) },
+ { &flags, sizeof(d2tk_flag_t) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
D2TK_CORE_WIDGET(core, hash, widget)
{
@@ -1637,9 +1648,12 @@ d2tk_base_cursor(d2tk_base_t *base, const d2tk_rect_t *rect)
d2tk_core_t *core = base->core;
const d2tk_style_t *style = d2tk_base_get_style(base);
- const uint64_t hash = d2tk_hash_foreach(rect, sizeof(rect),
- style, sizeof(d2tk_style_t),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { rect, sizeof(rect) },
+ { style, sizeof(d2tk_style_t) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
D2TK_CORE_WIDGET(core, hash, widget)
{
@@ -1874,9 +1888,12 @@ d2tk_base_image(d2tk_base_t *base, ssize_t path_len, const char *path,
path_len = strlen(path);
}
- const uint64_t hash = d2tk_hash_foreach(rect, sizeof(d2tk_rect_t),
- (path ? path : NULL), (path ? path_len : 0),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { rect, sizeof(d2tk_rect_t) },
+ { (path ? path : NULL), (path ? path_len : 0) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
d2tk_core_t *core = base->core;;
@@ -1898,12 +1915,15 @@ d2tk_base_bitmap(d2tk_base_t *base, uint32_t w, uint32_t h, uint32_t stride,
const uint32_t *argb, uint64_t rev, const d2tk_rect_t *rect,
d2tk_align_t align)
{
- const uint64_t hash = d2tk_hash_foreach(rect, sizeof(d2tk_rect_t),
- &w, sizeof(uint32_t),
- &h, sizeof(uint32_t),
- &stride, sizeof(uint32_t),
- &rev, sizeof(uint64_t),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { rect, sizeof(d2tk_rect_t) },
+ { &w, sizeof(uint32_t) },
+ { &h, sizeof(uint32_t) },
+ { &stride, sizeof(uint32_t) },
+ { &rev, sizeof(uint64_t) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
d2tk_core_t *core = base->core;;
@@ -1921,9 +1941,12 @@ D2TK_API void
d2tk_base_custom(d2tk_base_t *base, uint32_t size, const void *data,
const d2tk_rect_t *rect, d2tk_core_custom_t custom)
{
- const uint64_t hash = d2tk_hash_foreach(rect, sizeof(d2tk_rect_t),
- data, size, //FIXME
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { rect, sizeof(d2tk_rect_t) } ,
+ { data, size }, //FIXME
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
d2tk_core_t *core = base->core;;
@@ -1941,11 +1964,14 @@ static inline void
_d2tk_base_draw_meter(d2tk_core_t *core, const d2tk_rect_t *rect,
d2tk_state_t state, int32_t value, const d2tk_style_t *style)
{
- const uint64_t hash = d2tk_hash_foreach(&state, sizeof(d2tk_state_t),
- rect, sizeof(d2tk_rect_t),
- style, sizeof(d2tk_style_t),
- &value, sizeof(int32_t),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { &state, sizeof(d2tk_state_t) },
+ { rect, sizeof(d2tk_rect_t) },
+ { style, sizeof(d2tk_style_t) },
+ { &value, sizeof(int32_t) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
D2TK_CORE_WIDGET(core, hash, widget)
{
@@ -2150,13 +2176,16 @@ _d2tk_base_draw_combo(d2tk_core_t *core, ssize_t nitms, const char **itms,
const d2tk_rect_t *rect, d2tk_state_t state, int32_t value,
const d2tk_style_t *style)
{
- const uint64_t hash = d2tk_hash_foreach(&state, sizeof(d2tk_state_t),
- rect, sizeof(d2tk_rect_t),
- style, sizeof(d2tk_style_t),
- &value, sizeof(int32_t),
- &nitms, sizeof(ssize_t),
- itms, sizeof(const char **), //FIXME we should actually cache the labels
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { &state, sizeof(d2tk_state_t) },
+ { rect, sizeof(d2tk_rect_t) },
+ { style, sizeof(d2tk_style_t) },
+ { &value, sizeof(int32_t) },
+ { &nitms, sizeof(ssize_t) },
+ { itms, sizeof(const char **) }, //FIXME we should actually cache the labels
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
D2TK_CORE_WIDGET(core, hash, widget)
{
@@ -2378,12 +2407,15 @@ _d2tk_base_draw_text_field(d2tk_core_t *core, d2tk_state_t state,
const d2tk_rect_t *rect, const d2tk_style_t *style, char *value,
d2tk_align_t align)
{
- const uint64_t hash = d2tk_hash_foreach(&state, sizeof(d2tk_state_t),
- rect, sizeof(d2tk_rect_t),
- style, sizeof(d2tk_style_t),
- &align, sizeof(d2tk_align_t),
- value, -1,
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { &state, sizeof(d2tk_state_t) },
+ { rect, sizeof(d2tk_rect_t) },
+ { style, sizeof(d2tk_style_t) },
+ { &align, sizeof(d2tk_align_t) },
+ { value, strlen(value) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
D2TK_CORE_WIDGET(core, hash, widget)
{
@@ -2563,27 +2595,32 @@ D2TK_API d2tk_state_t
d2tk_base_label(d2tk_base_t *base, ssize_t lbl_len, const char *lbl,
float mul, const d2tk_rect_t *rect, d2tk_align_t align)
{
+ const bool has_lbl = lbl_len && lbl;
+
+ if(has_lbl && (lbl_len == -1) ) // zero terminated string
+ {
+ lbl_len = strlen(lbl);
+ }
+
const d2tk_style_t *style = d2tk_base_get_style(base);
- d2tk_core_t *core = base->core;
+ const d2tk_hash_dict_t dict [] = {
+ { rect, sizeof(d2tk_rect_t) },
+ { style, sizeof(d2tk_style_t) },
+ { lbl, lbl_len },
+ { &mul, sizeof(float) },
+ { &align, sizeof(d2tk_align_t) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
- const uint64_t hash = d2tk_hash_foreach(rect, sizeof(d2tk_rect_t),
- style, sizeof(d2tk_style_t),
- lbl, lbl_len,
- &mul, sizeof(float),
- &align, sizeof(d2tk_align_t),
- NULL);
+ d2tk_core_t *core = base->core;
D2TK_CORE_WIDGET(core, hash, widget)
{
d2tk_rect_t bnd;
d2tk_rect_shrink(&bnd, rect, style->padding);
- if(lbl_len == -1) // zero terminated string
- {
- lbl_len = strlen(lbl);
- }
-
const d2tk_triple_t triple = D2TK_TRIPLE_NONE;
const size_t ref = d2tk_core_bbox_push(core, true, rect);
@@ -2632,11 +2669,14 @@ d2tk_base_dial_bool(d2tk_base_t *base, d2tk_id_t id, const d2tk_rect_t *rect,
const d2tk_style_t *style = d2tk_base_get_style(base);
d2tk_core_t *core = base->core;
- const uint64_t hash = d2tk_hash_foreach(&state, sizeof(d2tk_state_t),
- rect, sizeof(d2tk_rect_t),
- style, sizeof(d2tk_style_t),
- value, sizeof(bool),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { &state, sizeof(d2tk_state_t) },
+ { rect, sizeof(d2tk_rect_t) },
+ { style, sizeof(d2tk_style_t) },
+ { value, sizeof(bool) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
D2TK_CORE_WIDGET(core, hash, widget)
{
@@ -2702,11 +2742,14 @@ static inline void
_d2tk_base_draw_dial(d2tk_core_t *core, const d2tk_rect_t *rect,
d2tk_state_t state, float rel, const d2tk_style_t *style)
{
- const uint64_t hash = d2tk_hash_foreach(&state, sizeof(d2tk_state_t),
- rect, sizeof(d2tk_rect_t),
- style, sizeof(d2tk_style_t),
- &rel, sizeof(float),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { &state, sizeof(d2tk_state_t) },
+ { rect, sizeof(d2tk_rect_t) },
+ { style, sizeof(d2tk_style_t) },
+ { &rel, sizeof(float) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
D2TK_CORE_WIDGET(core, hash, widget)
{
@@ -3097,11 +3140,14 @@ _d2tk_flowmatrix_connect(d2tk_base_t *base, d2tk_flowmatrix_t *flowmatrix,
d2tk_base_get_mouse_pos(base, &dst.x, &dst.y);
}
- const uint64_t hash = d2tk_hash_foreach(flowmatrix, sizeof(d2tk_flowmatrix_t),
- src_pos, sizeof(d2tk_pos_t),
- dst_pos ? dst_pos : &dst, sizeof(d2tk_pos_t),
- style, sizeof(d2tk_style_t),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { flowmatrix, sizeof(d2tk_flowmatrix_t) },
+ { src_pos, sizeof(d2tk_pos_t) },
+ { dst_pos ? dst_pos : &dst, sizeof(d2tk_pos_t) },
+ { style, sizeof(d2tk_style_t) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
d2tk_core_t *core = base->core;
D2TK_CORE_WIDGET(core, hash, widget)
@@ -3340,11 +3386,14 @@ d2tk_flowmatrix_node_begin(d2tk_base_t *base, d2tk_flowmatrix_t *flowmatrix,
const d2tk_style_t *style = d2tk_base_get_style(base);
- const uint64_t hash = d2tk_hash_foreach(flowmatrix, sizeof(d2tk_flowmatrix_t),
- pos, sizeof(d2tk_pos_t),
- node, sizeof(d2tk_flowmatrix_node_t),
- style, sizeof(d2tk_style_t),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { flowmatrix, sizeof(d2tk_flowmatrix_t) },
+ { pos, sizeof(d2tk_pos_t) },
+ { node, sizeof(d2tk_flowmatrix_node_t) },
+ { style, sizeof(d2tk_style_t) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
D2TK_CORE_WIDGET(core, hash, widget)
{
@@ -3493,15 +3542,18 @@ d2tk_flowmatrix_arc_begin(d2tk_base_t *base, d2tk_flowmatrix_t *flowmatrix,
const d2tk_style_t *style = d2tk_base_get_style(base);
- const uint64_t hash = d2tk_hash_foreach(flowmatrix, sizeof(d2tk_flowmatrix_t),
- &N, sizeof(unsigned),
- &M, sizeof(unsigned),
- src, sizeof(d2tk_pos_t),
- dst, sizeof(d2tk_pos_t),
- pos, sizeof(d2tk_pos_t),
- arc, sizeof(d2tk_flowmatrix_arc_t),
- style, sizeof(d2tk_style_t),
- NULL);
+ const d2tk_hash_dict_t dict [] = {
+ { flowmatrix, sizeof(d2tk_flowmatrix_t) },
+ { &N, sizeof(unsigned) },
+ { &M, sizeof(unsigned) },
+ { src, sizeof(d2tk_pos_t) },
+ { dst, sizeof(d2tk_pos_t) },
+ { pos, sizeof(d2tk_pos_t) },
+ { arc, sizeof(d2tk_flowmatrix_arc_t) },
+ { style, sizeof(d2tk_style_t) },
+ { NULL, 0 }
+ };
+ const uint64_t hash = d2tk_hash_dict(dict);
d2tk_core_t *core = base->core;
D2TK_CORE_WIDGET(core, hash, widget)
diff --git a/src/mum.c b/src/mum.c
index 146ea3c..49825a3 100644
--- a/src/mum.c
+++ b/src/mum.c
@@ -25,13 +25,6 @@
#define SEED 12345
__attribute__((always_inline))
-static inline size_t
-_len(const void *key, ssize_t len)
-{
- return (len == -1) ? strlen((const char *)key) : (size_t)len;
-}
-
-__attribute__((always_inline))
static inline uint64_t
_d2tk_hash(uint64_t hash, const void *key, size_t len)
{
@@ -41,8 +34,6 @@ _d2tk_hash(uint64_t hash, const void *key, size_t len)
D2TK_API uint64_t
d2tk_hash(const void *key, ssize_t len)
{
- len = _len(key, len);
-
return mum_hash(key, len, SEED);
}
@@ -52,15 +43,13 @@ d2tk_hash_foreach(const void *key, ssize_t len, ...)
va_list args;
uint64_t hash = mum_hash_init(SEED);
- len = _len(key, len); //FIXME remove
hash = _d2tk_hash(hash, key, len);
va_start(args, len);
while( (key = va_arg(args, const void *)) )
{
- len = _len(key, va_arg(args, int)); //FIXME remove
- hash = _d2tk_hash(hash, key, len);
+ hash = _d2tk_hash(hash, key, va_arg(args, size_t));
}
va_end(args);