diff options
author | ZyX <kp-pav@yandex.ru> | 2016-06-24 17:07:10 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2016-06-24 17:07:10 +0300 |
commit | 50f5bb8ade138a1a7a67838f01b7edb2f7396b92 (patch) | |
tree | 3ad6ca0bfcafce5de03bf2506945622937719557 | |
parent | 0d56118d862f0a366da57c82a6e995f1a51b0fc7 (diff) | |
download | rneovim-50f5bb8ade138a1a7a67838f01b7edb2f7396b92.tar.gz rneovim-50f5bb8ade138a1a7a67838f01b7edb2f7396b92.tar.bz2 rneovim-50f5bb8ade138a1a7a67838f01b7edb2f7396b92.zip |
kvec: Do not bother with making capacity a power of 2
This avoids gcc warnings about undefined behaviour.
-rw-r--r-- | src/nvim/lib/kvec.h | 11 |
1 files changed, 7 insertions, 4 deletions
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 /// |