This commit is contained in:
@@ -34,6 +34,14 @@
|
||||
#define EV_VEC_GROWTH_RATE 3 / 2
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef EV_VEC_MIN_CAPACITY
|
||||
/*!
|
||||
* \brief Minimum capacity used by vector when growing
|
||||
*/
|
||||
#define EV_VEC_MIN_CAPACITY 4
|
||||
#endif
|
||||
|
||||
#if EV_CC_MSVC
|
||||
# define __EV_VEC_EMPTY_ARRAY { 0 }
|
||||
#else
|
||||
@@ -304,6 +312,10 @@ ev_vec_dup(
|
||||
* vector, then this function is used. Otherwise, memcpy is used with a length
|
||||
* of `vec_meta.elemsize`
|
||||
*
|
||||
* \warning Having a free_fn defined for the elemtype but no copy_fn could have some
|
||||
* unwanted side effects as the free function will be called on the popped element
|
||||
* after copying it to `out`
|
||||
*
|
||||
* \param vec_p Reference to the vector object
|
||||
* \param out A pointer to the memory block at which the popped element will be
|
||||
* copied. If NULL is passed, then the element is destructed. Otherwise, the
|
||||
@@ -719,6 +731,9 @@ ev_vec_setlen(
|
||||
ev_vec_t* v = (ev_vec_t*)vec_p;
|
||||
__ev_vec_getmeta(*v)
|
||||
|
||||
while(metadata->length > len)
|
||||
ev_vec_pop(vec_p, NULL);
|
||||
|
||||
while(len > metadata->capacity) {
|
||||
ev_vec_error_t grow_err = ev_vec_grow(v);
|
||||
if(grow_err) {
|
||||
@@ -747,6 +762,10 @@ ev_vec_setcapacity(
|
||||
return EV_VEC_ERR_NONE;
|
||||
}
|
||||
|
||||
if(metadata->length > cap) {
|
||||
ev_vec_setlen(vec_p, cap);
|
||||
}
|
||||
|
||||
void *buf = ((char *)(*v) - sizeof(struct ev_vec_meta_t));
|
||||
void *tmp = realloc(buf, sizeof(struct ev_vec_meta_t) + (cap * metadata->typeData.size));
|
||||
|
||||
@@ -770,7 +789,8 @@ ev_vec_grow(
|
||||
{
|
||||
ev_vec_t* v = (ev_vec_t*)vec_p;
|
||||
__ev_vec_getmeta(*v)
|
||||
return ev_vec_setcapacity(v, metadata->capacity * EV_VEC_GROWTH_RATE);
|
||||
u64 new_cap = max(EV_VEC_MIN_CAPACITY, metadata->capacity * EV_VEC_GROWTH_RATE);
|
||||
return ev_vec_setcapacity(v, new_cap);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user