common/utils.h: add tal_arr_expand helper.

We do this a lot, and had boutique helpers in various places.  So add
a more generic one; for convenience it returns a pointer to the new
end element.

I prefer the name tal_arr_expand to tal_arr_append, since it's up to
the caller to populate the new array entry.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2018-09-27 09:49:24 +09:30
committed by Christian Decker
parent d590302523
commit 96f05549b2
23 changed files with 111 additions and 209 deletions

View File

@@ -23,10 +23,7 @@ static bool param_add(struct param **params,
if (!(name && cbx && arg))
return false;
#endif
struct param *last;
tal_resize(params, tal_count(*params) + 1);
last = &(*params)[tal_count(*params) - 1];
struct param *last = tal_arr_expand(params);
last->is_set = false;
last->name = name;