diff options
| author | Patrick Steinhardt <ps@pks.im> | 2017-06-07 09:50:54 +0200 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2017-06-08 11:58:22 +0200 |
| commit | 9a8386a2c649fa74cf90fe95931bc3fc0466f2f6 (patch) | |
| tree | 977ee2137aaaab425e633b5f76b394c8706f591a /src/buffer.c | |
| parent | e82dd8130fa1d944b5846f5165a990b97b2590ed (diff) | |
| download | libgit2-9a8386a2c649fa74cf90fe95931bc3fc0466f2f6.tar.gz | |
buffer: consistently use `ENSURE_SIZE` to grow buffers on-demand
The `ENSURE_SIZE` macro can be used to grow a buffer if its currently
allocated size does not suffice a required target size. While most of
the code already uses this macro, the `git_buf_join` and `git_buf_join3`
functions do not yet use it. Due to the macro first checking whether we
have to grow the buffer at all, this has the benefit of saving a
function call when it is not needed. While this is nice to have, it will
probably not matter at all performance-wise -- instead, this only serves
for consistency across the code.
Diffstat (limited to 'src/buffer.c')
| -rw-r--r-- | src/buffer.c | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/src/buffer.c b/src/buffer.c index ba8bd82d0..40bed5c98 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -724,9 +724,7 @@ int git_buf_join( GITERR_CHECK_ALLOC_ADD(&alloc_len, strlen_a, strlen_b); GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, need_sep); GITERR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 1); - if (git_buf_grow(buf, alloc_len) < 0) - return -1; - assert(buf->ptr); + ENSURE_SIZE(buf, alloc_len); /* fix up internal pointers */ if (offset_a >= 0) @@ -780,8 +778,7 @@ int git_buf_join3( GITERR_CHECK_ALLOC_ADD(&len_total, len_total, sep_b); GITERR_CHECK_ALLOC_ADD(&len_total, len_total, len_c); GITERR_CHECK_ALLOC_ADD(&len_total, len_total, 1); - if (git_buf_grow(buf, len_total) < 0) - return -1; + ENSURE_SIZE(buf, len_total); tgt = buf->ptr; |
