Use pointer-to-pointer idiom to construct linked list
This commit is contained in:
parent
c6111b3792
commit
8acef2711b
|
@ -227,8 +227,8 @@ int nghttp2_bufs_wrap_init2(nghttp2_bufs *bufs, uint8_t *const *bufs_in,
|
||||||
size_t in_len, size_t buf_len, nghttp2_mem *mem) {
|
size_t in_len, size_t buf_len, nghttp2_mem *mem) {
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
nghttp2_buf_chain *cur_chain;
|
nghttp2_buf_chain *cur_chain;
|
||||||
nghttp2_buf_chain *pre_chain = NULL;
|
|
||||||
nghttp2_buf_chain *head_chain = NULL;
|
nghttp2_buf_chain *head_chain = NULL;
|
||||||
|
nghttp2_buf_chain **dst_chain = &head_chain;
|
||||||
|
|
||||||
for (i = 0; i < in_len; ++i) {
|
for (i = 0; i < in_len; ++i) {
|
||||||
uint8_t *begin = bufs_in[i];
|
uint8_t *begin = bufs_in[i];
|
||||||
|
@ -246,13 +246,8 @@ int nghttp2_bufs_wrap_init2(nghttp2_bufs *bufs, uint8_t *const *bufs_in,
|
||||||
cur_chain->next = NULL;
|
cur_chain->next = NULL;
|
||||||
nghttp2_buf_wrap_init(&cur_chain->buf, begin, buf_len);
|
nghttp2_buf_wrap_init(&cur_chain->buf, begin, buf_len);
|
||||||
|
|
||||||
if (pre_chain) {
|
*dst_chain = cur_chain;
|
||||||
pre_chain->next = cur_chain;
|
dst_chain = &cur_chain->next;
|
||||||
} else {
|
|
||||||
head_chain = cur_chain;
|
|
||||||
}
|
|
||||||
|
|
||||||
pre_chain = cur_chain;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bufs->mem = mem;
|
bufs->mem = mem;
|
||||||
|
|
Loading…
Reference in New Issue