aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/lib/kvec.h
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2016-05-01 04:53:15 +0300
committerZyX <kp-pav@yandex.ru>2016-05-30 21:14:39 +0300
commit8cfb272c74b760c5c6224bc7b73358d982e117ab (patch)
tree079debbc0c1b1542986dad575213e1a7eb90fc19 /src/nvim/lib/kvec.h
parent748898b4dd992c5a5d15a0e1f9f047fc42ba4fd3 (diff)
downloadrneovim-8cfb272c74b760c5c6224bc7b73358d982e117ab.tar.gz
rneovim-8cfb272c74b760c5c6224bc7b73358d982e117ab.tar.bz2
rneovim-8cfb272c74b760c5c6224bc7b73358d982e117ab.zip
lib/kvec: Remove useless type argument from kv_push macros
Diffstat (limited to 'src/nvim/lib/kvec.h')
-rw-r--r--src/nvim/lib/kvec.h84
1 files changed, 50 insertions, 34 deletions
diff --git a/src/nvim/lib/kvec.h b/src/nvim/lib/kvec.h
index b41ef0cc9f..92a1232354 100644
--- a/src/nvim/lib/kvec.h
+++ b/src/nvim/lib/kvec.h
@@ -28,20 +28,20 @@
#include "kvec.h"
int main() {
- kvec_t(int) array;
- kv_init(array);
- kv_push(int, array, 10); // append
- kv_a(int, array, 20) = 5; // dynamic
- kv_A(array, 20) = 4; // static
- kv_destroy(array);
- return 0;
+ kvec_t(int) array;
+ kv_init(array);
+ kv_push(array, 10); // append
+ kv_a(array, 20) = 5; // dynamic
+ kv_A(array, 20) = 4; // static
+ kv_destroy(array);
+ return 0;
}
*/
/*
2008-09-22 (0.1.0):
- * The initial version.
+ * The initial version.
*/
@@ -62,31 +62,47 @@ int main() {
#define kv_max(v) ((v).capacity)
#define kv_last(v) kv_A(v, kv_size(v) - 1)
-#define kv_resize(type, v, s) ((v).capacity = (s), (v).items = (type*)xrealloc((v).items, sizeof(type) * (v).capacity))
-
-#define kv_copy(type, v1, v0) do { \
- if ((v1).capacity < (v0).size) kv_resize(type, v1, (v0).size); \
- (v1).size = (v0).size; \
- memcpy((v1).items, (v0).items, sizeof(type) * (v0).size); \
- } while (0) \
-
-#define kv_push(type, v, x) do { \
- if ((v).size == (v).capacity) { \
- (v).capacity = (v).capacity? (v).capacity<<1 : 8; \
- (v).items = (type*)xrealloc((v).items, sizeof(type) * (v).capacity); \
- } \
- (v).items[(v).size++] = (x); \
- } while (0)
-
-#define kv_pushp(type, v) ((((v).size == (v).capacity)? \
- ((v).capacity = ((v).capacity? (v).capacity<<1 : 8), \
- (v).items = (type*)xrealloc((v).items, sizeof(type) * (v).capacity), 0) \
- : 0), ((v).items + ((v).size++)))
-
-#define kv_a(type, v, i) (((v).capacity <= (size_t)(i)? \
- ((v).capacity = (v).size = (i) + 1, kv_roundup32((v).capacity), \
- (v).items = (type*)xrealloc((v).items, sizeof(type) * (v).capacity), 0) \
- : (v).size <= (size_t)(i)? (v).size = (i) + 1 \
- : 0), (v).items[(i)])
+#define kv_resize(v, s) \
+ do { \
+ (v).capacity = (s); \
+ (v).items = xrealloc((v).items, sizeof((v).items[0]) * (v).capacity); \
+ } while (0)
+
+#define kv_copy(v1, v0) \
+ do { \
+ if ((v1).capacity < (v0).size) { \
+ kv_resize(v1, (v0).size); \
+ } \
+ (v1).size = (v0).size; \
+ memcpy((v1).items, (v0).items, sizeof((v1).items[0]) * (v0).size); \
+ } while (0) \
+
+#define kv_push(v, x) \
+ do { \
+ if ((v).size == (v).capacity) { \
+ (v).capacity = (v).capacity ? (v).capacity << 1 : 8; \
+ (v).items = xrealloc((v).items, sizeof((v).items[0]) * (v).capacity); \
+ } \
+ (v).items[(v).size++] = (x); \
+ } while (0)
+
+#define kv_pushp(v) \
+ ((((v).size == (v).capacity) \
+ ? ((v).capacity = ((v).capacity ? (v).capacity << 1 : 8), \
+ (v).items = xrealloc((v).items, sizeof((v).items[0]) * (v).capacity), \
+ 0) \
+ : 0), \
+ ((v).items + ((v).size++)))
+
+#define kv_a(v, i) \
+ (((v).capacity <= (size_t) (i) \
+ ? ((v).capacity = (v).size = (i) + 1, \
+ kv_roundup32((v).capacity), \
+ (v).items = xrealloc((v).items, sizeof((v).items[0]) * (v).capacity), \
+ 0) \
+ : ((v).size <= (size_t)(i) \
+ ? (v).size = (i) + 1 \
+ : 0)), \
+ (v).items[(i)])
#endif