From 50f5bb8ade138a1a7a67838f01b7edb2f7396b92 Mon Sep 17 00:00:00 2001 From: ZyX Date: Fri, 24 Jun 2016 17:07:10 +0300 Subject: kvec: Do not bother with making capacity a power of 2 This avoids gcc warnings about undefined behaviour. --- src/nvim/lib/kvec.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/lib/kvec.h b/src/nvim/lib/kvec.h index 36c91c86b2..584282d773 100644 --- a/src/nvim/lib/kvec.h +++ b/src/nvim/lib/kvec.h @@ -134,6 +134,9 @@ static inline void *_memcpy_free(void *const restrict dest, /// 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[in] s New size. #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. */ \ /* 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 */ \ - /* capacity is not guaranteed to have size that is a power of 2. */ \ - kvi_resize(v, ((v).capacity == ARRAY_SIZE((v).init_array) \ - ? ((v).capacity++, kv_roundup32((v).capacity)) \ - : (v).capacity << 1)) + /* capacity is not guaranteed to have size that is a power of 2, it is */ \ + /* hard to fix this here and is not very necessary if users will use */ \ + /* 2^x initial array size. */ \ + kvi_resize(v, (v).capacity << 1) /// Get location where to store new element to a vector with preallocated array /// -- cgit