kvec: Do not bother with making capacity a power of 2

This avoids gcc warnings about undefined behaviour.
This commit is contained in:
ZyX
2016-06-24 17:07:10 +03:00
parent 0d56118d86
commit 50f5bb8ade

View File

@@ -134,6 +134,9 @@ static inline void *_memcpy_free(void *const restrict dest,
/// Resize vector with preallocated array /// Resize vector with preallocated array
/// ///
/// @note May not resize to an array smaller then init_array: if requested,
/// init_array will be used.
///
/// @param[out] v Vector to resize. /// @param[out] v Vector to resize.
/// @param[in] s New size. /// @param[in] s New size.
#define kvi_resize(v, s) \ #define kvi_resize(v, s) \
@@ -159,10 +162,10 @@ static inline void *_memcpy_free(void *const restrict dest,
/* ARRAY_SIZE((v).init_array) is the minimal capacity of this vector. */ \ /* ARRAY_SIZE((v).init_array) is the minimal capacity of this vector. */ \
/* Thus when vector is full capacity may not be zero and it is safe */ \ /* Thus when vector is full capacity may not be zero and it is safe */ \
/* not to bother with checking whether (v).capacity is 0. But now */ \ /* not to bother with checking whether (v).capacity is 0. But now */ \
/* capacity is not guaranteed to have size that is a power of 2. */ \ /* capacity is not guaranteed to have size that is a power of 2, it is */ \
kvi_resize(v, ((v).capacity == ARRAY_SIZE((v).init_array) \ /* hard to fix this here and is not very necessary if users will use */ \
? ((v).capacity++, kv_roundup32((v).capacity)) \ /* 2^x initial array size. */ \
: (v).capacity << 1)) kvi_resize(v, (v).capacity << 1)
/// Get location where to store new element to a vector with preallocated array /// Get location where to store new element to a vector with preallocated array
/// ///