diff options
author | Joshua Haberman <jhaberman@gmail.com> | 2019-01-15 14:48:09 -0800 |
---|---|---|
committer | Joshua Haberman <jhaberman@gmail.com> | 2019-01-15 14:48:09 -0800 |
commit | 2c26f60dbbc49bca6233cc20a15ff4b32454c6e8 (patch) | |
tree | ed3457ac04b937d8738f481e698cf001578880a9 /upb/handlers.c | |
parent | 9349b703a33c76b0d50a15c6d372e8948e045749 (diff) |
Added some comments and reversed upb_arena_cleanup() args.
Diffstat (limited to 'upb/handlers.c')
-rw-r--r-- | upb/handlers.c | 21 |
1 files changed, 1 insertions, 20 deletions
diff --git a/upb/handlers.c b/upb/handlers.c index aa23b46..7abf948 100644 --- a/upb/handlers.c +++ b/upb/handlers.c @@ -392,7 +392,6 @@ uint32_t upb_handlers_selectorcount(const upb_fielddef *f) { struct upb_handlercache { upb_arena *arena; upb_inttable tab; /* maps upb_msgdef* -> upb_handlers*. */ - upb_inttable cleanup_; upb_handlers_callback *callback; const void *closure; }; @@ -448,7 +447,6 @@ upb_handlercache *upb_handlercache_new(upb_handlers_callback *callback, cache->closure = closure; if (!upb_inttable_init(&cache->tab, UPB_CTYPE_PTR)) goto oom; - if (!upb_inttable_init(&cache->cleanup_, UPB_CTYPE_FPTR)) goto oom; return cache; @@ -458,31 +456,14 @@ oom: } void upb_handlercache_free(upb_handlercache *cache) { - upb_inttable_iter i; - - upb_inttable_begin(&i, &cache->cleanup_); - for(; !upb_inttable_done(&i); upb_inttable_next(&i)) { - void *val = (void*)upb_inttable_iter_key(&i); - upb_value func_val = upb_inttable_iter_value(&i); - upb_handlerfree *func = upb_value_getfptr(func_val); - func(val); - } - upb_inttable_uninit(&cache->tab); - upb_inttable_uninit(&cache->cleanup_); upb_arena_free(cache->arena); upb_gfree(cache); } bool upb_handlercache_addcleanup(upb_handlercache *c, void *p, upb_handlerfree *func) { - bool ok; - if (upb_inttable_lookupptr(&c->cleanup_, p, NULL)) { - return false; - } - ok = upb_inttable_insertptr(&c->cleanup_, p, upb_value_fptr(func)); - UPB_ASSERT(ok); - return true; + return upb_arena_addcleanup(c->arena, p, func); } /* upb_byteshandler ***********************************************************/ |