diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-10-04 06:14:28 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-10-04 06:29:27 +0300 |
commit | 74a2fa309555da9b76abdc205cec43909872fc20 (patch) | |
tree | 2bb8a658c2282b7af1b8738278530822152047c3 /source/blender/blenlib/BLI_buffer.h | |
parent | 9f046e95c0a5c4b842d7405111ebab90e1ba63b6 (diff) |
BLI_Buffer: add BLI_buffer_reinit
Useful for re-using a buffer when the existing data can be thrown away.
Diffstat (limited to 'source/blender/blenlib/BLI_buffer.h')
-rw-r--r-- | source/blender/blenlib/BLI_buffer.h | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/source/blender/blenlib/BLI_buffer.h b/source/blender/blenlib/BLI_buffer.h index 941c1c93ae9..a9ecd3a4627 100644 --- a/source/blender/blenlib/BLI_buffer.h +++ b/source/blender/blenlib/BLI_buffer.h @@ -64,7 +64,7 @@ enum { #define BLI_buffer_at(buffer_, type_, index_) ( \ (((type_ *)(buffer_)->data)[ \ (BLI_assert(sizeof(type_) == (buffer_)->elem_size)), \ - (BLI_assert(index_ >= 0 && index_ < (buffer_)->count)), \ + (BLI_assert((int)index_ >= 0 && (size_t)index_ < (buffer_)->count)), \ index_])) #define BLI_buffer_array(buffer_, type_) ( \ @@ -73,6 +73,9 @@ enum { #define BLI_buffer_resize_data(buffer_, type_, new_count_) ( \ (BLI_buffer_resize(buffer_, new_count_), new_count_ ? BLI_buffer_array(buffer_, type_) : NULL)) +#define BLI_buffer_reinit_data(buffer_, type_, new_count_) ( \ + (BLI_buffer_reinit(buffer_, new_count_), new_count_ ? BLI_buffer_array(buffer_, type_) : NULL)) + #define BLI_buffer_append(buffer_, type_, val_) ( \ BLI_buffer_resize(buffer_, (buffer_)->count + 1), \ (BLI_buffer_at(buffer_, type_, (buffer_)->count - 1) = val_) \ @@ -85,6 +88,9 @@ enum { /* Never decreases the amount of memory allocated */ void BLI_buffer_resize(BLI_Buffer *buffer, const size_t new_count); +/* Ensure size, throwing away old data, respecting BLI_BUFFER_USE_CALLOC */ +void BLI_buffer_reinit(BLI_Buffer *buffer, const size_t new_count); + /* Does not free the buffer structure itself */ void _bli_buffer_free(BLI_Buffer *buffer); #define BLI_buffer_free(name_) { \ |