From db4d92891c78cdf32753b022b7081dd9a32d8aa6 Mon Sep 17 00:00:00 2001 From: Sean Barrett Date: Mon, 29 Jan 2018 07:44:04 -0800 Subject: [PATCH] fix stb_sdict_for() --- stb.h | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/stb.h b/stb.h index c6a39f3..5a4e0de 100644 --- a/stb.h +++ b/stb.h @@ -4246,12 +4246,22 @@ STB_EXTERN void stb_sdict_delete(stb_sdict *); STB_EXTERN void * stb_sdict_change(stb_sdict *, char *str, void *p); STB_EXTERN int stb_sdict_count(stb_sdict *d); +STB_EXTERN int stb_sdict_internal_limit(stb_sdict *d); +STB_EXTERN char * stb_sdict_internal_key(stb_sdict *d, int n); +STB_EXTERN void * stb_sdict_internal_value(stb_sdict *d, int n); + #define stb_sdict_for(d,i,q,z) \ - for(i=0; i < (d)->limit ? q=(d)->table[i].k,z=(d)->table[i].v,1 : 0; ++i) \ + for(i=0; i < stb_sdict_internal_limit(d) ? (q=stb_sdict_internal_key(d,i),z=stb_sdict_internal_value(d,i),1) : 0; ++i) \ if (q==NULL||q==(void *) 1);else // reversed makes macro friendly #ifdef STB_DEFINE +// if in same translation unit, for speed, don't call accessors +#undef stb_sdict_for +#define stb_sdict_for(d,i,q,z) \ + for(i=0; i < (d)->limit ? (q=(d)->table[i].k,z=(d)->table[i].v,1) : 0; ++i) \ + if (q==NULL||q==(void *) 1);else // reversed makes macro friendly + #define STB_DEL ((void *) 1) #define STB_SDEL ((char *) 1) @@ -4271,6 +4281,19 @@ int stb_sdict_count(stb_sdict *a) return a->count; } +int stb_sdict_internal_limit(stb_sdict *a) +{ + return a->limit; +} +char* stb_sdict_internal_key(stb_sdict *a, int n) +{ + return a->table[n].k; +} +void* stb_sdict_internal_value(stb_sdict *a, int n) +{ + return a->table[n].v; +} + stb_sdict * stb_sdict_new(int use_arena) { stb_sdict *d = stb_sdict_create();