lib/kvec: Remove useless type argument from kv_push macros

This commit is contained in:
ZyX
2016-05-01 04:53:15 +03:00
parent 748898b4dd
commit 8cfb272c74
7 changed files with 65 additions and 51 deletions

View File

@@ -62,12 +62,10 @@
#define NIL ((Object) {.type = kObjectTypeNil}) #define NIL ((Object) {.type = kObjectTypeNil})
#define PUT(dict, k, v) \ #define PUT(dict, k, v) \
kv_push(KeyValuePair, \ kv_push(dict, ((KeyValuePair) { .key = cstr_to_string(k), .value = v }))
dict, \
((KeyValuePair) {.key = cstr_to_string(k), .value = v}))
#define ADD(array, item) \ #define ADD(array, item) \
kv_push(Object, array, item) kv_push(array, item)
#define STATIC_CSTR_AS_STRING(s) ((String) {.data = s, .size = sizeof(s) - 1}) #define STATIC_CSTR_AS_STRING(s) ((String) {.data = s, .size = sizeof(s) - 1})

View File

@@ -4950,7 +4950,7 @@ int bufhl_add_hl(buf_T *buf,
bufhl_vec_T* lineinfo = map_ref(linenr_T, bufhl_vec_T)(buf->b_bufhl_info, bufhl_vec_T* lineinfo = map_ref(linenr_T, bufhl_vec_T)(buf->b_bufhl_info,
lnum, true); lnum, true);
bufhl_hl_item_T *hlentry = kv_pushp(bufhl_hl_item_T, *lineinfo); bufhl_hl_item_T *hlentry = kv_pushp(*lineinfo);
hlentry->src_id = src_id; hlentry->src_id = src_id;
hlentry->hl_id = hl_id; hlentry->hl_id = hl_id;
hlentry->start = col_start; hlentry->start = col_start;

View File

@@ -101,7 +101,7 @@ static inline int json_decoder_pop(ValuesStackItem obj,
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
if (kv_size(*container_stack) == 0) { if (kv_size(*container_stack) == 0) {
kv_push(ValuesStackItem, *stack, obj); kv_push(*stack, obj);
return OK; return OK;
} }
ContainerStackItem last_container = kv_last(*container_stack); ContainerStackItem last_container = kv_last(*container_stack);
@@ -190,7 +190,7 @@ static inline int json_decoder_pop(ValuesStackItem obj,
*next_map_special = true; *next_map_special = true;
return OK; return OK;
} }
kv_push(ValuesStackItem, *stack, obj); kv_push(*stack, obj);
} }
return OK; return OK;
} }
@@ -815,13 +815,13 @@ json_decode_string_cycle_start:
.v_lock = VAR_UNLOCKED, .v_lock = VAR_UNLOCKED,
.vval = { .v_list = list }, .vval = { .v_list = list },
}; };
kv_push(ContainerStackItem, container_stack, ((ContainerStackItem) { kv_push(container_stack, ((ContainerStackItem) {
.stack_index = kv_size(stack), .stack_index = kv_size(stack),
.s = p, .s = p,
.container = tv, .container = tv,
.special_val = NULL, .special_val = NULL,
})); }));
kv_push(ValuesStackItem, stack, OBJ(tv, false, didcomma, didcolon)); kv_push(stack, OBJ(tv, false, didcomma, didcolon));
break; break;
} }
case '{': { case '{': {
@@ -845,13 +845,13 @@ json_decode_string_cycle_start:
.vval = { .v_dict = dict }, .vval = { .v_dict = dict },
}; };
} }
kv_push(ContainerStackItem, container_stack, ((ContainerStackItem) { kv_push(container_stack, ((ContainerStackItem) {
.stack_index = kv_size(stack), .stack_index = kv_size(stack),
.s = p, .s = p,
.container = tv, .container = tv,
.special_val = val_list, .special_val = val_list,
})); }));
kv_push(ValuesStackItem, stack, OBJ(tv, false, didcomma, didcolon)); kv_push(stack, OBJ(tv, false, didcomma, didcolon));
break; break;
} }
default: { default: {

View File

@@ -333,7 +333,7 @@ static int name##_convert_one_value(firstargtype firstargname, \
} \ } \
CHECK_SELF_REFERENCE(tv->vval.v_list, lv_copyID, kMPConvList); \ CHECK_SELF_REFERENCE(tv->vval.v_list, lv_copyID, kMPConvList); \
CONV_LIST_START(tv->vval.v_list); \ CONV_LIST_START(tv->vval.v_list); \
kv_push(MPConvStackVal, *mpstack, ((MPConvStackVal) { \ kv_push(*mpstack, ((MPConvStackVal) { \
.type = kMPConvList, \ .type = kMPConvList, \
.data = { \ .data = { \
.l = { \ .l = { \
@@ -464,7 +464,7 @@ static int name##_convert_one_value(firstargtype firstargname, \
CHECK_SELF_REFERENCE(val_di->di_tv.vval.v_list, lv_copyID, \ CHECK_SELF_REFERENCE(val_di->di_tv.vval.v_list, lv_copyID, \
kMPConvList); \ kMPConvList); \
CONV_LIST_START(val_di->di_tv.vval.v_list); \ CONV_LIST_START(val_di->di_tv.vval.v_list); \
kv_push(MPConvStackVal, *mpstack, ((MPConvStackVal) { \ kv_push(*mpstack, ((MPConvStackVal) { \
.type = kMPConvList, \ .type = kMPConvList, \
.data = { \ .data = { \
.l = { \ .l = { \
@@ -493,7 +493,7 @@ static int name##_convert_one_value(firstargtype firstargname, \
} \ } \
CHECK_SELF_REFERENCE(val_list, lv_copyID, kMPConvPairs); \ CHECK_SELF_REFERENCE(val_list, lv_copyID, kMPConvPairs); \
CONV_DICT_START(val_list->lv_len); \ CONV_DICT_START(val_list->lv_len); \
kv_push(MPConvStackVal, *mpstack, ((MPConvStackVal) { \ kv_push(*mpstack, ((MPConvStackVal) { \
.type = kMPConvPairs, \ .type = kMPConvPairs, \
.data = { \ .data = { \
.l = { \ .l = { \
@@ -532,7 +532,7 @@ static int name##_convert_one_value(firstargtype firstargname, \
name##_convert_one_value_regular_dict: \ name##_convert_one_value_regular_dict: \
CHECK_SELF_REFERENCE(tv->vval.v_dict, dv_copyID, kMPConvDict); \ CHECK_SELF_REFERENCE(tv->vval.v_dict, dv_copyID, kMPConvDict); \
CONV_DICT_START(tv->vval.v_dict->dv_hashtab.ht_used); \ CONV_DICT_START(tv->vval.v_dict->dv_hashtab.ht_used); \
kv_push(MPConvStackVal, *mpstack, ((MPConvStackVal) { \ kv_push(*mpstack, ((MPConvStackVal) { \
.type = kMPConvDict, \ .type = kMPConvDict, \
.data = { \ .data = { \
.d = { \ .d = { \

View File

@@ -28,20 +28,20 @@
#include "kvec.h" #include "kvec.h"
int main() { int main() {
kvec_t(int) array; kvec_t(int) array;
kv_init(array); kv_init(array);
kv_push(int, array, 10); // append kv_push(array, 10); // append
kv_a(int, array, 20) = 5; // dynamic kv_a(array, 20) = 5; // dynamic
kv_A(array, 20) = 4; // static kv_A(array, 20) = 4; // static
kv_destroy(array); kv_destroy(array);
return 0; return 0;
} }
*/ */
/* /*
2008-09-22 (0.1.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_max(v) ((v).capacity)
#define kv_last(v) kv_A(v, kv_size(v) - 1) #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_resize(v, s) \
do { \
(v).capacity = (s); \
(v).items = xrealloc((v).items, sizeof((v).items[0]) * (v).capacity); \
} while (0)
#define kv_copy(type, v1, v0) do { \ #define kv_copy(v1, v0) \
if ((v1).capacity < (v0).size) kv_resize(type, v1, (v0).size); \ do { \
(v1).size = (v0).size; \ if ((v1).capacity < (v0).size) { \
memcpy((v1).items, (v0).items, sizeof(type) * (v0).size); \ kv_resize(v1, (v0).size); \
} while (0) \ } \
(v1).size = (v0).size; \
memcpy((v1).items, (v0).items, sizeof((v1).items[0]) * (v0).size); \
} while (0) \
#define kv_push(type, v, x) do { \ #define kv_push(v, x) \
if ((v).size == (v).capacity) { \ do { \
(v).capacity = (v).capacity? (v).capacity<<1 : 8; \ if ((v).size == (v).capacity) { \
(v).items = (type*)xrealloc((v).items, sizeof(type) * (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) (v).items[(v).size++] = (x); \
} while (0)
#define kv_pushp(type, v) ((((v).size == (v).capacity)? \ #define kv_pushp(v) \
((v).capacity = ((v).capacity? (v).capacity<<1 : 8), \ ((((v).size == (v).capacity) \
(v).items = (type*)xrealloc((v).items, sizeof(type) * (v).capacity), 0) \ ? ((v).capacity = ((v).capacity ? (v).capacity << 1 : 8), \
: 0), ((v).items + ((v).size++))) (v).items = xrealloc((v).items, sizeof((v).items[0]) * (v).capacity), \
0) \
: 0), \
((v).items + ((v).size++)))
#define kv_a(type, v, i) (((v).capacity <= (size_t)(i)? \ #define kv_a(v, i) \
((v).capacity = (v).size = (i) + 1, kv_roundup32((v).capacity), \ (((v).capacity <= (size_t) (i) \
(v).items = (type*)xrealloc((v).items, sizeof(type) * (v).capacity), 0) \ ? ((v).capacity = (v).size = (i) + 1, \
: (v).size <= (size_t)(i)? (v).size = (i) + 1 \ kv_roundup32((v).capacity), \
: 0), (v).items[(i)]) (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 #endif

View File

@@ -179,7 +179,7 @@ bool channel_send_event(uint64_t id, char *name, Array args)
// Pending request, queue the notification for later sending. // Pending request, queue the notification for later sending.
String method = cstr_as_string(name); String method = cstr_as_string(name);
WBuffer *buffer = serialize_request(id, 0, method, args, &out_buffer, 1); WBuffer *buffer = serialize_request(id, 0, method, args, &out_buffer, 1);
kv_push(WBuffer *, channel->delayed_notifications, buffer); kv_push(channel->delayed_notifications, buffer);
} else { } else {
send_event(channel, name, args); send_event(channel, name, args);
} }
@@ -217,8 +217,8 @@ Object channel_send_call(uint64_t id,
send_request(channel, request_id, method_name, args); send_request(channel, request_id, method_name, args);
// Push the frame // Push the frame
ChannelCallFrame frame = {request_id, false, false, NIL}; ChannelCallFrame frame = { request_id, false, false, NIL };
kv_push(ChannelCallFrame *, channel->call_stack, &frame); kv_push(channel->call_stack, &frame);
channel->pending_requests++; channel->pending_requests++;
LOOP_PROCESS_EVENTS_UNTIL(&loop, channel->events, -1, frame.returned); LOOP_PROCESS_EVENTS_UNTIL(&loop, channel->events, -1, frame.returned);
(void)kv_pop(channel->call_stack); (void)kv_pop(channel->call_stack);
@@ -580,7 +580,7 @@ static void broadcast_event(char *name, Array args)
map_foreach_value(channels, channel, { map_foreach_value(channels, channel, {
if (pmap_has(cstr_t)(channel->subscribed_events, name)) { if (pmap_has(cstr_t)(channel->subscribed_events, name)) {
kv_push(Channel *, subscribed, channel); kv_push(subscribed, channel);
} }
}); });
@@ -600,7 +600,7 @@ static void broadcast_event(char *name, Array args)
for (size_t i = 0; i < kv_size(subscribed); i++) { for (size_t i = 0; i < kv_size(subscribed); i++) {
Channel *channel = kv_A(subscribed, i); Channel *channel = kv_A(subscribed, i);
if (channel->pending_requests) { if (channel->pending_requests) {
kv_push(WBuffer *, channel->delayed_notifications, buffer); kv_push(channel->delayed_notifications, buffer);
} else { } else {
channel_write(channel, buffer); channel_write(channel, buffer);
} }

View File

@@ -681,7 +681,7 @@ static void invalidate(UI *ui, int top, int bot, int left, int right)
intersects->right = MAX(right, intersects->right); intersects->right = MAX(right, intersects->right);
} else { } else {
// Else just add a new entry; // Else just add a new entry;
kv_push(Rect, data->invalid_regions, ((Rect){top, bot, left, right})); kv_push(data->invalid_regions, ((Rect) { top, bot, left, right }));
} }
} }