diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-09-06 09:30:50 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-11-02 10:00:32 -0400 |
commit | 095e15f8ac8216cd945b85c159b461d8cd0697a3 (patch) | |
tree | 03ea07fa01949a4a29d841f9f930aad4c95598ac /src/common/buffers.c | |
parent | 5240d02a110f280ab9071657a66dedfc617aef0c (diff) | |
download | tor-095e15f8ac8216cd945b85c159b461d8cd0697a3.tar.gz tor-095e15f8ac8216cd945b85c159b461d8cd0697a3.zip |
Add a zero-copy buffer move implementation.
Diffstat (limited to 'src/common/buffers.c')
-rw-r--r-- | src/common/buffers.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/common/buffers.c b/src/common/buffers.c index d7c4e4d8c3..d1725cf1a1 100644 --- a/src/common/buffers.c +++ b/src/common/buffers.c @@ -838,6 +838,28 @@ buf_move_to_buf(buf_t *buf_out, buf_t *buf_in, size_t *buf_flushlen) return (int)cp; } +/** Moves all data from <b>buf_in</b> to <b>buf_out</b>, without copying. + */ +void +buf_move_all(buf_t *buf_out, buf_t *buf_in) +{ + tor_assert(buf_out); + if (!buf_in) + return; + + if (buf_out->head == NULL) { + buf_out->head = buf_in->head; + buf_out->tail = buf_in->tail; + } else { + buf_out->tail->next = buf_in->head; + buf_out->tail = buf_in->tail; + } + + buf_out->datalen += buf_in->datalen; + buf_in->head = buf_in->tail = NULL; + buf_in->datalen = 0; +} + /** Internal structure: represents a position in a buffer. */ typedef struct buf_pos_t { const chunk_t *chunk; /**< Which chunk are we pointing to? */ |