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 PUT(dict, k, v) \
kv_push(KeyValuePair, \
dict, \
((KeyValuePair) {.key = cstr_to_string(k), .value = v}))
kv_push(dict, ((KeyValuePair) { .key = cstr_to_string(k), .value = v }))
#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})

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,
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->hl_id = hl_id;
hlentry->start = col_start;

View File

@@ -101,7 +101,7 @@ static inline int json_decoder_pop(ValuesStackItem obj,
FUNC_ATTR_NONNULL_ALL
{
if (kv_size(*container_stack) == 0) {
kv_push(ValuesStackItem, *stack, obj);
kv_push(*stack, obj);
return OK;
}
ContainerStackItem last_container = kv_last(*container_stack);
@@ -190,7 +190,7 @@ static inline int json_decoder_pop(ValuesStackItem obj,
*next_map_special = true;
return OK;
}
kv_push(ValuesStackItem, *stack, obj);
kv_push(*stack, obj);
}
return OK;
}
@@ -815,13 +815,13 @@ json_decode_string_cycle_start:
.v_lock = VAR_UNLOCKED,
.vval = { .v_list = list },
};
kv_push(ContainerStackItem, container_stack, ((ContainerStackItem) {
kv_push(container_stack, ((ContainerStackItem) {
.stack_index = kv_size(stack),
.s = p,
.container = tv,
.special_val = NULL,
}));
kv_push(ValuesStackItem, stack, OBJ(tv, false, didcomma, didcolon));
kv_push(stack, OBJ(tv, false, didcomma, didcolon));
break;
}
case '{': {
@@ -845,13 +845,13 @@ json_decode_string_cycle_start:
.vval = { .v_dict = dict },
};
}
kv_push(ContainerStackItem, container_stack, ((ContainerStackItem) {
kv_push(container_stack, ((ContainerStackItem) {
.stack_index = kv_size(stack),
.s = p,
.container = tv,
.special_val = val_list,
}));
kv_push(ValuesStackItem, stack, OBJ(tv, false, didcomma, didcolon));
kv_push(stack, OBJ(tv, false, didcomma, didcolon));
break;
}
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); \
CONV_LIST_START(tv->vval.v_list); \
kv_push(MPConvStackVal, *mpstack, ((MPConvStackVal) { \
kv_push(*mpstack, ((MPConvStackVal) { \
.type = kMPConvList, \
.data = { \
.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, \
kMPConvList); \
CONV_LIST_START(val_di->di_tv.vval.v_list); \
kv_push(MPConvStackVal, *mpstack, ((MPConvStackVal) { \
kv_push(*mpstack, ((MPConvStackVal) { \
.type = kMPConvList, \
.data = { \
.l = { \
@@ -493,7 +493,7 @@ static int name##_convert_one_value(firstargtype firstargname, \
} \
CHECK_SELF_REFERENCE(val_list, lv_copyID, kMPConvPairs); \
CONV_DICT_START(val_list->lv_len); \
kv_push(MPConvStackVal, *mpstack, ((MPConvStackVal) { \
kv_push(*mpstack, ((MPConvStackVal) { \
.type = kMPConvPairs, \
.data = { \
.l = { \
@@ -532,7 +532,7 @@ static int name##_convert_one_value(firstargtype firstargname, \
name##_convert_one_value_regular_dict: \
CHECK_SELF_REFERENCE(tv->vval.v_dict, dv_copyID, kMPConvDict); \
CONV_DICT_START(tv->vval.v_dict->dv_hashtab.ht_used); \
kv_push(MPConvStackVal, *mpstack, ((MPConvStackVal) { \
kv_push(*mpstack, ((MPConvStackVal) { \
.type = kMPConvDict, \
.data = { \
.d = { \

View File

@@ -30,8 +30,8 @@
int main() {
kvec_t(int) array;
kv_init(array);
kv_push(int, array, 10); // append
kv_a(int, array, 20) = 5; // dynamic
kv_push(array, 10); // append
kv_a(array, 20) = 5; // dynamic
kv_A(array, 20) = 4; // static
kv_destroy(array);
return 0;
@@ -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_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 { \
if ((v1).capacity < (v0).size) kv_resize(type, v1, (v0).size); \
#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(type) * (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) \
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).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(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_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(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_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

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.
String method = cstr_as_string(name);
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 {
send_event(channel, name, args);
}
@@ -217,8 +217,8 @@ Object channel_send_call(uint64_t id,
send_request(channel, request_id, method_name, args);
// Push the frame
ChannelCallFrame frame = {request_id, false, false, NIL};
kv_push(ChannelCallFrame *, channel->call_stack, &frame);
ChannelCallFrame frame = { request_id, false, false, NIL };
kv_push(channel->call_stack, &frame);
channel->pending_requests++;
LOOP_PROCESS_EVENTS_UNTIL(&loop, channel->events, -1, frame.returned);
(void)kv_pop(channel->call_stack);
@@ -580,7 +580,7 @@ static void broadcast_event(char *name, Array args)
map_foreach_value(channels, channel, {
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++) {
Channel *channel = kv_A(subscribed, i);
if (channel->pending_requests) {
kv_push(WBuffer *, channel->delayed_notifications, buffer);
kv_push(channel->delayed_notifications, buffer);
} else {
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);
} else {
// 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 }));
}
}