diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/private/helpers.h | 6 | ||||
-rw-r--r-- | src/nvim/buffer.c | 2 | ||||
-rw-r--r-- | src/nvim/eval/decode.c | 12 | ||||
-rw-r--r-- | src/nvim/eval/encode.c | 8 | ||||
-rw-r--r-- | src/nvim/lib/kvec.h | 84 | ||||
-rw-r--r-- | src/nvim/msgpack_rpc/channel.c | 10 | ||||
-rw-r--r-- | src/nvim/tui/tui.c | 2 |
7 files changed, 69 insertions, 55 deletions
diff --git a/src/nvim/api/private/helpers.h b/src/nvim/api/private/helpers.h index a0f14ac7a4..7ed726c7ce 100644 --- a/src/nvim/api/private/helpers.h +++ b/src/nvim/api/private/helpers.h @@ -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}) diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 72716daf0e..a1f2439e0a 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -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; diff --git a/src/nvim/eval/decode.c b/src/nvim/eval/decode.c index 0774ef515f..4a4a697e73 100644 --- a/src/nvim/eval/decode.c +++ b/src/nvim/eval/decode.c @@ -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: { diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c index c651a50be9..da000bf670 100644 --- a/src/nvim/eval/encode.c +++ b/src/nvim/eval/encode.c @@ -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 = { \ 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 diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c index 3a6d7c1434..f6d437dee7 100644 --- a/src/nvim/msgpack_rpc/channel.c +++ b/src/nvim/msgpack_rpc/channel.c @@ -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); } diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 62bc81ba64..fe1a864067 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -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 })); } } |