mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 01:24:26 +01:00
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:
committed by
Christian Decker
parent
d590302523
commit
96f05549b2
@@ -1,6 +1,7 @@
|
||||
#include <assert.h>
|
||||
#include <ccan/take/take.h>
|
||||
#include <common/msg_queue.h>
|
||||
#include <common/utils.h>
|
||||
#include <wire/wire.h>
|
||||
|
||||
void msg_queue_init(struct msg_queue *q, const tal_t *ctx)
|
||||
@@ -11,9 +12,7 @@ void msg_queue_init(struct msg_queue *q, const tal_t *ctx)
|
||||
|
||||
static void do_enqueue(struct msg_queue *q, const u8 *add)
|
||||
{
|
||||
size_t n = tal_count(q->q);
|
||||
tal_resize(&q->q, n+1);
|
||||
q->q[n] = tal_dup_arr(q->ctx, u8, add, tal_count(add), 0);
|
||||
*tal_arr_expand(&q->q) = tal_dup_arr(q->ctx, u8, add, tal_count(add), 0);
|
||||
|
||||
/* In case someone is waiting */
|
||||
io_wake(q);
|
||||
|
||||
Reference in New Issue
Block a user