diff options
author | Chris Robinson <[email protected]> | 2014-03-21 16:35:38 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-03-21 16:35:38 -0700 |
commit | 8c33b4d742087a3467caba5d049368e5e301eff3 (patch) | |
tree | eddb440ba1f170338f03c599e38139fd3f67943d /Alc/vector.h | |
parent | 983fa4630a8ba68f2e446cc0b05234fd5399c9bd (diff) |
Increase the vector reserve as needed when pushing in new items
Diffstat (limited to 'Alc/vector.h')
-rw-r--r-- | Alc/vector.h | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/Alc/vector.h b/Alc/vector.h index bcf9166d..de89bbe0 100644 --- a/Alc/vector.h +++ b/Alc/vector.h @@ -21,8 +21,8 @@ typedef struct vector__s { #define VECTOR_DEINIT(_x) do { free(_x); _x = NULL; } while(0) /* Helper to increase a vector's reserve. Do not call directly. */ -ALboolean vector_reserve(void *ptr, size_t orig_count, size_t base_size, size_t obj_count, size_t obj_size); -#define VECTOR_RESERVE(_x, _c) (vector_reserve(&(_x), (_x)->Capacity, sizeof(*(_x)), (_c), sizeof((_x)->Data[0]))) +ALboolean vector_reserve(void *ptr, size_t orig_count, size_t base_size, size_t obj_count, size_t obj_size, ALboolean exact); +#define VECTOR_RESERVE(_x, _c) (vector_reserve(&(_x), (_x)->Capacity, sizeof(*(_x)), (_c), sizeof((_x)->Data[0]), AL_TRUE)) #define VECTOR_CAPACITY(_x) ((const ALsizei)(_x)->Capacity) #define VECTOR_SIZE(_x) ((const ALsizei)(_x)->Size) @@ -30,8 +30,8 @@ ALboolean vector_reserve(void *ptr, size_t orig_count, size_t base_size, size_t #define VECTOR_ITER_BEGIN(_x) ((_x)->Data) #define VECTOR_ITER_END(_x) ((_x)->Data + (_x)->Size) -/* NOTE: The caller must ensure enough space is reserved before pushing in new objects. */ -#define VECTOR_PUSH_BACK(_x, _obj) ((void)((_x)->Data[(_x)->Size++] = (_obj))) +#define VECTOR_PUSH_BACK(_x, _obj) (vector_reserve(&(_x), (_x)->Capacity, sizeof(*(_x)), (_x)->Size+1, sizeof((_x)->Data[0]), AL_FALSE) && \ + (((_x)->Data[(_x)->Size++] = (_obj)),AL_TRUE)) #define VECTOR_POP_BACK(_x) ((void)((_x)->Size--)) #define VECTOR_BACK(_x) ((_x)->Data[(_x)->Size-1]) |