aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/buffer.c2
-rw-r--r--src/nvim/buffer_defs.h8
-rw-r--r--src/nvim/eval.c40
-rw-r--r--src/nvim/ex_getln.c36
-rw-r--r--src/nvim/globals.h4
-rw-r--r--src/nvim/lib/khash.h437
-rw-r--r--src/nvim/main.c2
-rw-r--r--src/nvim/mark.c78
-rw-r--r--src/nvim/mark_defs.h2
-rw-r--r--src/nvim/ops.c4
-rw-r--r--src/nvim/option.c3
-rw-r--r--src/nvim/search.c2
-rw-r--r--src/nvim/search.h2
13 files changed, 341 insertions, 279 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index d0fad0e002..b3eba4f5f6 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -1995,7 +1995,7 @@ buflist_nr2name (
///
/// @param[in,out] buf Buffer for which line and column are set.
/// @param[in,out] win Window for which line and column are set.
-/// @param[in] lnum Line number to be set. If it is zero then only
+/// @param[in] lnum Line number to be set. If it is zero then only
/// options are touched.
/// @param[in] col Column number to be set.
/// @param[in] copy_options If true save the local window option values.
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index f71575deaf..3eabb7ee43 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -512,10 +512,10 @@ struct file_buffer {
visualinfo_T b_visual;
int b_visual_mode_eval; /* b_visual.vi_mode for visualmode() */
- fmark_T b_last_cursor; /* cursor position when last unloading this
- buffer */
- fmark_T b_last_insert; /* where Insert mode was left */
- fmark_T b_last_change; /* position of last change: '. mark */
+ fmark_T b_last_cursor; // cursor position when last unloading this
+ // buffer
+ fmark_T b_last_insert; // where Insert mode was left
+ fmark_T b_last_change; // position of last change: '. mark
/*
* the changelist contains old change positions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index d2d195155d..d02348028a 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -5340,7 +5340,7 @@ static int list_concat(list_T *l1, list_T *l2, typval_T *tv)
return FAIL;
/* make a copy of the first list. */
- l = list_copy(NULL, l1, FALSE, 0);
+ l = list_copy(NULL, l1, false, 0);
if (l == NULL)
return FAIL;
tv->v_type = VAR_LIST;
@@ -5358,7 +5358,7 @@ static int list_concat(list_T *l1, list_T *l2, typval_T *tv)
/// @param[in] deep If false, then shallow copy will be done.
/// @param[in] copyID See var_item_copy().
///
-/// @return Copied list. May be NULL in case original list is NULL or some
+/// @return Copied list. May be NULL in case original list is NULL or some
/// failure happens. The refcount of the new list is set to 1.
static list_T *list_copy(const vimconv_T *const conv,
list_T *const orig,
@@ -6089,8 +6089,8 @@ void dictitem_free(dictitem_T *item)
/// @param[in] deep If false, then shallow copy will be done.
/// @param[in] copyID See var_item_copy().
///
-/// @return Copied dictionary. May be NULL in case original dictionary is NULL
-/// or some failure happens. The refcount of the new dictionary is set
+/// @return Copied dictionary. May be NULL in case original dictionary is NULL
+/// or some failure happens. The refcount of the new dictionary is set
/// to 1.
static dict_T *dict_copy(const vimconv_T *const conv,
dict_T *const orig,
@@ -18591,21 +18591,21 @@ void copy_tv(typval_T *from, typval_T *to)
/// @param[in] conv If not NULL, convert all copied strings.
/// @param[in] from Value to copy.
/// @param[out] to Location where to copy to.
-/// @param[in] deep If true, use copy the container and all of the contained
+/// @param[in] deep If true, use copy the container and all of the contained
/// containers (nested).
-/// @param[in] copyID If non-zero then when container is referenced more then
-/// once then copy of it that was already done is used. E.g.
-/// when copying list `list = [list2, list2]` (`list[0] is
-/// list[1]`) var_item_copy with zero copyID will emit
-/// a copy with (`copy[0] isnot copy[1]`), with non-zero it
-/// will emit a copy with (`copy[0] is copy[1]`) like in the
+/// @param[in] copyID If non-zero then when container is referenced more then
+/// once then copy of it that was already done is used. E.g.
+/// when copying list `list = [list2, list2]` (`list[0] is
+/// list[1]`) var_item_copy with zero copyID will emit
+/// a copy with (`copy[0] isnot copy[1]`), with non-zero it
+/// will emit a copy with (`copy[0] is copy[1]`) like in the
/// original list. Not use when deep is false.
int var_item_copy(const vimconv_T *const conv,
typval_T *const from,
typval_T *const to,
const bool deep,
const int copyID)
- FUNC_ATTR_NONNULL_ARG(2,3)
+ FUNC_ATTR_NONNULL_ARG(2, 3)
{
static int recurse = 0;
int ret = OK;
@@ -18645,8 +18645,9 @@ int var_item_copy(const vimconv_T *const conv,
/* use the copy made earlier */
to->vval.v_list = from->vval.v_list->lv_copylist;
++to->vval.v_list->lv_refcount;
- } else
+ } else {
to->vval.v_list = list_copy(conv, from->vval.v_list, deep, copyID);
+ }
if (to->vval.v_list == NULL)
ret = FAIL;
break;
@@ -18659,8 +18660,9 @@ int var_item_copy(const vimconv_T *const conv,
/* use the copy made earlier */
to->vval.v_dict = from->vval.v_dict->dv_copydict;
++to->vval.v_dict->dv_refcount;
- } else
+ } else {
to->vval.v_dict = dict_copy(conv, from->vval.v_dict, deep, copyID);
+ }
if (to->vval.v_dict == NULL)
ret = FAIL;
break;
@@ -20875,23 +20877,25 @@ static var_flavour_T var_flavour(char_u *varname)
if (ASCII_ISUPPER(*p)) {
while (*(++p))
- if (ASCII_ISLOWER(*p))
+ if (ASCII_ISLOWER(*p)) {
return VAR_FLAVOUR_SESSION;
+ }
return VAR_FLAVOUR_SHADA;
- } else
+ } else {
return VAR_FLAVOUR_DEFAULT;
+ }
}
/// Iterate over global variables
///
-/// @warning No modifications to global variable dictionary must be performed
+/// @warning No modifications to global variable dictionary must be performed
/// while iteration is in progress.
///
/// @param[in] iter Iterator. Pass NULL to start iteration.
/// @param[out] name Variable name.
/// @param[out] rettv Variable value.
///
-/// @return Pointer that needs to be passed to next `var_shada_iter` invocation
+/// @return Pointer that needs to be passed to next `var_shada_iter` invocation
/// or NULL to indicate that iteration is over.
const void *var_shada_iter(const void *const iter, const char **const name,
typval_T *rettv)
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 2bfe574b1d..7998d7e823 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -4268,7 +4268,7 @@ static int
in_history (
int type,
char_u *str,
- int move_to_front, /* Move the entry to the front if it exists */
+ int move_to_front, // Move the entry to the front if it exists
int sep
)
{
@@ -4309,9 +4309,9 @@ in_history (
history[type][i].hisstr = str;
history[type][i].timestamp = os_time();
history[type][i].additional_elements = NULL;
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
/*
@@ -4378,7 +4378,7 @@ add_to_history (
}
last_maptick = -1;
}
- if (!in_history(histype, new_entry, TRUE, sep)) {
+ if (!in_history(histype, new_entry, true, sep)) {
if (++hisidx[histype] == hislen)
hisidx[histype] = 0;
hisptr = &history[histype][hisidx[histype]];
@@ -4548,7 +4548,7 @@ char_u *get_history_entry(int histype, int idx)
///
/// @param[in] histype One of the HIST_ values.
///
-/// @return OK if there was something to clean and histype was one of HIST_
+/// @return OK if there was something to clean and histype was one of HIST_
/// values, FAIL otherwise.
int clr_history(const int histype)
{
@@ -4575,7 +4575,7 @@ int del_history_entry(int histype, char_u *str)
int idx;
int i;
int last;
- int found = FALSE;
+ bool found = false;
regmatch.regprog = NULL;
regmatch.rm_ic = FALSE; /* always match case */
@@ -4592,7 +4592,7 @@ int del_history_entry(int histype, char_u *str)
if (hisptr->hisstr == NULL)
break;
if (vim_regexec(&regmatch, hisptr->hisstr, (colnr_T)0)) {
- found = TRUE;
+ found = true;
hist_free_entry(hisptr);
} else {
if (i != last) {
@@ -5077,24 +5077,24 @@ char_u *script_get(exarg_T *eap, char_u *cmd)
/// Iterate over history items
///
-/// @warning No history-editing functions must be run while iteration is in
+/// @warning No history-editing functions must be run while iteration is in
/// progress.
///
/// @param[in] iter Pointer to the last history entry.
-/// @param[in] history_type Type of the history (HIST_*). Ignored if iter
+/// @param[in] history_type Type of the history (HIST_*). Ignored if iter
/// parameter is not NULL.
/// @param[in] zero If true then zero (but not free) returned items.
///
-/// @warning When using this parameter user is
-/// responsible for calling clr_history()
-/// itself after iteration is over. If
-/// clr_history() is not called behaviour is
-/// undefined. No functions that work with
-/// history must be called during iteration
+/// @warning When using this parameter user is
+/// responsible for calling clr_history()
+/// itself after iteration is over. If
+/// clr_history() is not called behaviour is
+/// undefined. No functions that work with
+/// history must be called during iteration
/// in this case.
/// @param[out] hist Next history entry.
///
-/// @return Pointer used in next iteration or NULL to indicate that iteration
+/// @return Pointer used in next iteration or NULL to indicate that iteration
/// was finished.
const void *hist_iter(const void *const iter, const uint8_t history_type,
const bool zero, histentry_T *const hist)
@@ -5143,9 +5143,9 @@ const void *hist_iter(const void *const iter, const uint8_t history_type,
/// Get array of history items
///
/// @param[in] history_type Type of the history to get array for.
-/// @param[out] new_hisidx Location where last index in the new array should
+/// @param[out] new_hisidx Location where last index in the new array should
/// be saved.
-/// @param[out] new_hisnum Location where last history number in the new
+/// @param[out] new_hisnum Location where last history number in the new
/// history should be saved.
///
/// @return Pointer to the array or NULL.
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index 146109a414..0ef0a12889 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -891,8 +891,8 @@ EXTERN int must_redraw INIT(= 0); /* type of redraw necessary */
EXTERN int skip_redraw INIT(= FALSE); /* skip redraw once */
EXTERN int do_redraw INIT(= FALSE); /* extra redraw once */
-EXTERN int need_highlight_changed INIT(= TRUE);
-EXTERN char *used_shada_file INIT(= NULL); /* name of ShaDa file to use */
+EXTERN int need_highlight_changed INIT(= true);
+EXTERN char *used_shada_file INIT(= NULL); // name of the ShaDa file to use
#define NSCRIPT 15
EXTERN FILE *scriptin[NSCRIPT]; /* streams to read script from */
diff --git a/src/nvim/lib/khash.h b/src/nvim/lib/khash.h
index e45dcf2c80..56be29d14c 100644
--- a/src/nvim/lib/khash.h
+++ b/src/nvim/lib/khash.h
@@ -114,8 +114,8 @@ int main() {
*/
-#ifndef __AC_KHASH_H
-#define __AC_KHASH_H
+#ifndef NVIM_LIB_KHASH_H
+#define NVIM_LIB_KHASH_H
/*!
@header
@@ -194,175 +194,229 @@ static const double __ac_HASH_UPPER = 0.77;
khval_t *vals; \
} kh_##name##_t;
-#define __KHASH_PROTOTYPES(name, khkey_t, khval_t) \
- extern kh_##name##_t *kh_init_##name(void); \
- extern void kh_dealloc_##name(kh_##name##_t *h); \
- extern void kh_destroy_##name(kh_##name##_t *h); \
- extern void kh_clear_##name(kh_##name##_t *h); \
- extern khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key); \
- extern void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets); \
- extern khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret); \
- extern void kh_del_##name(kh_##name##_t *h, khint_t x);
-
-#define __KHASH_IMPL(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \
- SCOPE kh_##name##_t *kh_init_##name(void) \
- REAL_FATTR_UNUSED; \
- SCOPE kh_##name##_t *kh_init_##name(void) { \
- return (kh_##name##_t*)kcalloc(1, sizeof(kh_##name##_t)); \
- } \
- SCOPE void kh_dealloc_##name(kh_##name##_t *h) \
- REAL_FATTR_UNUSED; \
- SCOPE void kh_dealloc_##name(kh_##name##_t *h) \
- { \
- kfree((void *)h->keys); kfree(h->flags); \
- kfree((void *)h->vals); \
- } \
- SCOPE void kh_destroy_##name(kh_##name##_t *h) \
- REAL_FATTR_UNUSED; \
- SCOPE void kh_destroy_##name(kh_##name##_t *h) \
- { \
- if (h) { \
- kh_dealloc_##name(h); \
- kfree(h); \
- } \
- } \
- SCOPE void kh_clear_##name(kh_##name##_t *h) \
- REAL_FATTR_UNUSED; \
- SCOPE void kh_clear_##name(kh_##name##_t *h) \
- { \
- if (h && h->flags) { \
- memset(h->flags, 0xaa, __ac_fsize(h->n_buckets) * sizeof(khint32_t)); \
- h->size = h->n_occupied = 0; \
- } \
- } \
- SCOPE khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key) \
- REAL_FATTR_UNUSED; \
- SCOPE khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key) \
- { \
- if (h->n_buckets) { \
- khint_t k, i, last, mask, step = 0; \
- mask = h->n_buckets - 1; \
- k = __hash_func(key); i = k & mask; \
- last = i; \
- while (!__ac_isempty(h->flags, i) && (__ac_isdel(h->flags, i) || !__hash_equal(h->keys[i], key))) { \
- i = (i + (++step)) & mask; \
- if (i == last) return h->n_buckets; \
- } \
- return __ac_iseither(h->flags, i)? h->n_buckets : i; \
- } else return 0; \
- } \
- SCOPE void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \
- REAL_FATTR_UNUSED; \
- SCOPE void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \
- { /* This function uses 0.25*n_buckets bytes of working space instead of [sizeof(key_t+val_t)+.25]*n_buckets. */ \
- khint32_t *new_flags = 0; \
- khint_t j = 1; \
- { \
- kroundup32(new_n_buckets); \
- if (new_n_buckets < 4) new_n_buckets = 4; \
- if (h->size >= (khint_t)(new_n_buckets * __ac_HASH_UPPER + 0.5)) j = 0; /* requested size is too small */ \
- else { /* hash table size to be changed (shrink or expand); rehash */ \
- new_flags = (khint32_t*)kmalloc(__ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
- memset(new_flags, 0xaa, __ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
- if (h->n_buckets < new_n_buckets) { /* expand */ \
- khkey_t *new_keys = (khkey_t*)krealloc((void *)h->keys, new_n_buckets * sizeof(khkey_t)); \
- h->keys = new_keys; \
- if (kh_is_map) { \
- khval_t *new_vals = (khval_t*)krealloc((void *)h->vals, new_n_buckets * sizeof(khval_t)); \
- h->vals = new_vals; \
- } \
- } /* otherwise shrink */ \
- } \
- } \
- if (j) { /* rehashing is needed */ \
- for (j = 0; j != h->n_buckets; ++j) { \
- if (__ac_iseither(h->flags, j) == 0) { \
- khkey_t key = h->keys[j]; \
- khval_t val; \
- khint_t new_mask; \
- new_mask = new_n_buckets - 1; \
- if (kh_is_map) val = h->vals[j]; \
- __ac_set_isdel_true(h->flags, j); \
- while (1) { /* kick-out process; sort of like in Cuckoo hashing */ \
- khint_t k, i, step = 0; \
- k = __hash_func(key); \
- i = k & new_mask; \
- while (!__ac_isempty(new_flags, i)) i = (i + (++step)) & new_mask; \
- __ac_set_isempty_false(new_flags, i); \
- if (i < h->n_buckets && __ac_iseither(h->flags, i) == 0) { /* kick out the existing element */ \
- { khkey_t tmp = h->keys[i]; h->keys[i] = key; key = tmp; } \
- if (kh_is_map) { khval_t tmp = h->vals[i]; h->vals[i] = val; val = tmp; } \
- __ac_set_isdel_true(h->flags, i); /* mark it as deleted in the old hash table */ \
- } else { /* write the element and jump out of the loop */ \
- h->keys[i] = key; \
- if (kh_is_map) h->vals[i] = val; \
- break; \
- } \
- } \
- } \
- } \
- if (h->n_buckets > new_n_buckets) { /* shrink the hash table */ \
- h->keys = (khkey_t*)krealloc((void *)h->keys, new_n_buckets * sizeof(khkey_t)); \
- if (kh_is_map) h->vals = (khval_t*)krealloc((void *)h->vals, new_n_buckets * sizeof(khval_t)); \
- } \
- kfree(h->flags); /* free the working space */ \
- h->flags = new_flags; \
- h->n_buckets = new_n_buckets; \
- h->n_occupied = h->size; \
- h->upper_bound = (khint_t)(h->n_buckets * __ac_HASH_UPPER + 0.5); \
- } \
- } \
- SCOPE khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret) \
- REAL_FATTR_UNUSED; \
- SCOPE khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret) \
- { \
- khint_t x; \
- if (h->n_occupied >= h->upper_bound) { /* update the hash table */ \
- if (h->n_buckets > (h->size<<1)) { \
- kh_resize_##name(h, h->n_buckets - 1); /* clear "deleted" elements */ \
- } else { \
- kh_resize_##name(h, h->n_buckets + 1); /* expand the hash table */ \
- } \
- } /* TODO: to implement automatically shrinking; resize() already support shrinking */ \
- { \
- khint_t k, i, site, last, mask = h->n_buckets - 1, step = 0; \
- x = site = h->n_buckets; k = __hash_func(key); i = k & mask; \
- if (__ac_isempty(h->flags, i)) x = i; /* for speed up */ \
- else { \
- last = i; \
- while (!__ac_isempty(h->flags, i) && (__ac_isdel(h->flags, i) || !__hash_equal(h->keys[i], key))) { \
- if (__ac_isdel(h->flags, i)) site = i; \
- i = (i + (++step)) & mask; \
- if (i == last) { x = site; break; } \
- } \
- if (x == h->n_buckets) { \
- if (__ac_isempty(h->flags, i) && site != h->n_buckets) x = site; \
- else x = i; \
- } \
- } \
- } \
- if (__ac_isempty(h->flags, x)) { /* not present at all */ \
- h->keys[x] = key; \
- __ac_set_isboth_false(h->flags, x); \
- ++h->size; ++h->n_occupied; \
- *ret = 1; \
- } else if (__ac_isdel(h->flags, x)) { /* deleted */ \
- h->keys[x] = key; \
- __ac_set_isboth_false(h->flags, x); \
- ++h->size; \
- *ret = 2; \
- } else *ret = 0; /* Don't touch h->keys[x] if present and not deleted */ \
- return x; \
- } \
- SCOPE void kh_del_##name(kh_##name##_t *h, khint_t x) \
- REAL_FATTR_UNUSED; \
- SCOPE void kh_del_##name(kh_##name##_t *h, khint_t x) \
- { \
- if (x != h->n_buckets && !__ac_iseither(h->flags, x)) { \
- __ac_set_isdel_true(h->flags, x); \
- --h->size; \
- } \
- }
+#define __KHASH_PROTOTYPES(name, khkey_t, khval_t) \
+ extern kh_##name##_t *kh_init_##name(void); \
+ extern void kh_dealloc_##name(kh_##name##_t *h); \
+ extern void kh_destroy_##name(kh_##name##_t *h); \
+ extern void kh_clear_##name(kh_##name##_t *h); \
+ extern khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key); \
+ extern void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets); \
+ extern khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret); \
+ extern void kh_del_##name(kh_##name##_t *h, khint_t x);
+
+#define __KHASH_IMPL(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, \
+ __hash_equal) \
+ SCOPE kh_##name##_t *kh_init_##name(void) \
+ REAL_FATTR_UNUSED; \
+ SCOPE kh_##name##_t *kh_init_##name(void) { \
+ return (kh_##name##_t*)kcalloc(1, sizeof(kh_##name##_t)); \
+ } \
+ SCOPE void kh_dealloc_##name(kh_##name##_t *h) \
+ REAL_FATTR_UNUSED; \
+ SCOPE void kh_dealloc_##name(kh_##name##_t *h) \
+ { \
+ kfree(h->keys); \
+ kfree(h->flags); \
+ kfree(h->vals); \
+ } \
+ SCOPE void kh_destroy_##name(kh_##name##_t *h) \
+ REAL_FATTR_UNUSED; \
+ SCOPE void kh_destroy_##name(kh_##name##_t *h) \
+ { \
+ if (h) { \
+ kh_dealloc_##name(h); \
+ kfree(h); \
+ } \
+ } \
+ SCOPE void kh_clear_##name(kh_##name##_t *h) \
+ REAL_FATTR_UNUSED; \
+ SCOPE void kh_clear_##name(kh_##name##_t *h) \
+ { \
+ if (h && h->flags) { \
+ memset(h->flags, 0xaa, __ac_fsize(h->n_buckets) * sizeof(khint32_t)); \
+ h->size = h->n_occupied = 0; \
+ } \
+ } \
+ SCOPE khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key) \
+ REAL_FATTR_UNUSED; \
+ SCOPE khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key) \
+ { \
+ if (h->n_buckets) { \
+ khint_t k, i, last, mask, step = 0; \
+ mask = h->n_buckets - 1; \
+ k = __hash_func(key); i = k & mask; \
+ last = i; \
+ while (!__ac_isempty(h->flags, i) && (__ac_isdel(h->flags, i) || \
+ !__hash_equal(h->keys[i], key))) { \
+ i = (i + (++step)) & mask; \
+ if (i == last) { \
+ return h->n_buckets; \
+ } \
+ } \
+ return __ac_iseither(h->flags, i) ? h->n_buckets : i; \
+ } else { \
+ return 0; \
+ } \
+ } \
+ SCOPE void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \
+ REAL_FATTR_UNUSED; \
+ SCOPE void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \
+ { /* This function uses 0.25*n_buckets bytes of working space instead of */ \
+ /* [sizeof(key_t+val_t)+.25]*n_buckets. */ \
+ khint32_t *new_flags = 0; \
+ khint_t j = 1; \
+ { \
+ kroundup32(new_n_buckets); \
+ if (new_n_buckets < 4) { \
+ new_n_buckets = 4; \
+ } \
+ /* requested size is too small */ \
+ if (h->size >= (khint_t)(new_n_buckets * __ac_HASH_UPPER + 0.5)) { \
+ j = 0; \
+ } else { /* hash table size to be changed (shrink or expand); rehash */ \
+ new_flags = (khint32_t*)kmalloc(__ac_fsize(new_n_buckets) \
+ * sizeof(khint32_t)); \
+ memset(new_flags, 0xaa, \
+ __ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
+ if (h->n_buckets < new_n_buckets) { /* expand */ \
+ khkey_t *new_keys = (khkey_t*)krealloc( \
+ (void *)h->keys, new_n_buckets * sizeof(khkey_t)); \
+ h->keys = new_keys; \
+ if (kh_is_map) { \
+ khval_t *new_vals = (khval_t*)krealloc( \
+ (void *)h->vals, new_n_buckets * sizeof(khval_t)); \
+ h->vals = new_vals; \
+ } \
+ } /* otherwise shrink */ \
+ } \
+ } \
+ if (j) { /* rehashing is needed */ \
+ for (j = 0; j != h->n_buckets; ++j) { \
+ if (__ac_iseither(h->flags, j) == 0) { \
+ khkey_t key = h->keys[j]; \
+ khval_t val; \
+ khint_t new_mask; \
+ new_mask = new_n_buckets - 1; \
+ if (kh_is_map) { \
+ val = h->vals[j]; \
+ } \
+ __ac_set_isdel_true(h->flags, j); \
+ /* kick-out process; sort of like in Cuckoo hashing */ \
+ while (1) { \
+ khint_t k, i, step = 0; \
+ k = __hash_func(key); \
+ i = k & new_mask; \
+ while (!__ac_isempty(new_flags, i)) { \
+ i = (i + (++step)) & new_mask; \
+ } \
+ __ac_set_isempty_false(new_flags, i); \
+ /* kick out the existing element */ \
+ if (i < h->n_buckets && __ac_iseither(h->flags, i) == 0) { \
+ { \
+ khkey_t tmp = h->keys[i]; \
+ h->keys[i] = key; \
+ key = tmp; \
+ } \
+ if (kh_is_map) { \
+ khval_t tmp = h->vals[i]; \
+ h->vals[i] = val; \
+ val = tmp; \
+ } \
+ /* mark it as deleted in the old hash table */ \
+ __ac_set_isdel_true(h->flags, i); \
+ } else { /* write the element and jump out of the loop */ \
+ h->keys[i] = key; \
+ if (kh_is_map) { \
+ h->vals[i] = val; \
+ } \
+ break; \
+ } \
+ } \
+ } \
+ } \
+ if (h->n_buckets > new_n_buckets) { /* shrink the hash table */ \
+ h->keys = (khkey_t*)krealloc((void *)h->keys, \
+ new_n_buckets * sizeof(khkey_t)); \
+ if (kh_is_map) { \
+ h->vals = (khval_t*)krealloc((void *)h->vals, \
+ new_n_buckets * sizeof(khval_t)); \
+ } \
+ } \
+ kfree(h->flags); /* free the working space */ \
+ h->flags = new_flags; \
+ h->n_buckets = new_n_buckets; \
+ h->n_occupied = h->size; \
+ h->upper_bound = (khint_t)(h->n_buckets * __ac_HASH_UPPER + 0.5); \
+ } \
+ } \
+ SCOPE khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret) \
+ REAL_FATTR_UNUSED; \
+ SCOPE khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret) \
+ { \
+ khint_t x; \
+ if (h->n_occupied >= h->upper_bound) { /* update the hash table */ \
+ if (h->n_buckets > (h->size << 1)) { \
+ kh_resize_##name(h, h->n_buckets - 1); /* clear "deleted" elements */ \
+ } else { \
+ kh_resize_##name(h, h->n_buckets + 1); /* expand the hash table */ \
+ } \
+ } /* TODO: implement automatically shrinking; */ \
+ /* resize() already support shrinking */ \
+ { \
+ khint_t k, i, site, last, mask = h->n_buckets - 1, step = 0; \
+ x = site = h->n_buckets; \
+ k = __hash_func(key); \
+ i = k & mask; \
+ if (__ac_isempty(h->flags, i)) { \
+ x = i; /* for speed up */ \
+ } else { \
+ last = i; \
+ while (!__ac_isempty(h->flags, i) \
+ && (__ac_isdel(h->flags, i) \
+ || !__hash_equal(h->keys[i], key))) { \
+ if (__ac_isdel(h->flags, i)) { \
+ site = i; \
+ } \
+ i = (i + (++step)) & mask; \
+ if (i == last) { \
+ x = site; \
+ break; \
+ } \
+ } \
+ if (x == h->n_buckets) { \
+ if (__ac_isempty(h->flags, i) && site != h->n_buckets) { \
+ x = site; \
+ } else { \
+ x = i; \
+ } \
+ } \
+ } \
+ } \
+ if (__ac_isempty(h->flags, x)) { /* not present at all */ \
+ h->keys[x] = key; \
+ __ac_set_isboth_false(h->flags, x); \
+ h->size++; \
+ h->n_occupied++; \
+ *ret = 1; \
+ } else if (__ac_isdel(h->flags, x)) { /* deleted */ \
+ h->keys[x] = key; \
+ __ac_set_isboth_false(h->flags, x); \
+ h->size++; \
+ *ret = 2; \
+ } else { \
+ *ret = 0; /* Don't touch h->keys[x] if present and not deleted */ \
+ } \
+ return x; \
+ } \
+ SCOPE void kh_del_##name(kh_##name##_t *h, khint_t x) \
+ REAL_FATTR_UNUSED; \
+ SCOPE void kh_del_##name(kh_##name##_t *h, khint_t x) \
+ { \
+ if (x != h->n_buckets && !__ac_iseither(h->flags, x)) { \
+ __ac_set_isdel_true(h->flags, x); \
+ --h->size; \
+ } \
+ }
#define KHASH_DECLARE(name, khkey_t, khval_t) \
__KHASH_TYPE(name, khkey_t, khval_t) \
@@ -599,12 +653,17 @@ static kh_inline khint_t __ac_Wang_hash(khint_t key)
@param kvar Variable to which value will be assigned
@param code Block of code to execute
*/
-#define kh_foreach_key(h, kvar, code) { khint_t __i; \
- for (__i = kh_begin(h); __i != kh_end(h); ++__i) { \
- if (!kh_exist(h,__i)) continue; \
- (kvar) = kh_key(h,__i); \
- code; \
- } }
+#define kh_foreach_key(h, kvar, code) \
+ { \
+ khint_t __i; \
+ for (__i = kh_begin(h); __i != kh_end(h); __i++) { \
+ if (!kh_exist(h, __i)) { \
+ continue; \
+ } \
+ (kvar) = kh_key(h, __i); \
+ code; \
+ } \
+ }
/* More conenient interfaces */
@@ -651,21 +710,21 @@ typedef const char *kh_cstr_t;
@param name Name of the hash table [symbol]
@param khval_t Type of values [type]
*/
-#define KHASH_MAP_INIT_STR(name, khval_t) \
- KHASH_INIT(name, kh_cstr_t, khval_t, 1, kh_str_hash_func, kh_str_hash_equal)
+#define KHASH_MAP_INIT_STR(name, khval_t) \
+ KHASH_INIT(name, kh_cstr_t, khval_t, 1, kh_str_hash_func, kh_str_hash_equal)
/*! @function
@abstract Return a literal for an empty hash table.
@param name Name of the hash table [symbol]
*/
#define KHASH_EMPTY_TABLE(name) \
- ((kh_##name##_t) { \
- .n_buckets = 0, \
- .size = 0, \
- .n_occupied = 0, \
- .upper_bound = 0, \
- .flags = NULL, \
- .keys = NULL, \
- .vals = NULL, \
- })
-#endif /* __AC_KHASH_H */
+ ((kh_##name##_t) { \
+ .n_buckets = 0, \
+ .size = 0, \
+ .n_occupied = 0, \
+ .upper_bound = 0, \
+ .flags = NULL, \
+ .keys = NULL, \
+ .vals = NULL, \
+ })
+#endif // NVIM_LIB_KHASH_H
diff --git a/src/nvim/main.c b/src/nvim/main.c
index c4387c0b7f..d865260295 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -2042,7 +2042,7 @@ static void usage(void)
mch_msg(_(" -r, -L List swap files and exit\n"));
mch_msg(_(" -r <file> Recover crashed session\n"));
mch_msg(_(" -u <nvimrc> Use <nvimrc> instead of the default\n"));
- mch_msg(_(" -i <shada> Use <shada> instead of the default " SHADA_FILE "\n"));
+ mch_msg(_(" -i <shada> Use <shada> instead of the default " SHADA_FILE "\n")); // NOLINT(whitespace/line_length)
mch_msg(_(" --noplugin Don't load plugin scripts\n"));
mch_msg(_(" -o[N] Open N windows (default: one for each file)\n"));
mch_msg(_(" -O[N] Like -o but split vertically\n"));
diff --git a/src/nvim/mark.c b/src/nvim/mark.c
index db0f18c3a5..bf6ef33ae0 100644
--- a/src/nvim/mark.c
+++ b/src/nvim/mark.c
@@ -312,22 +312,21 @@ pos_T *getmark_buf_fnum(buf_T *buf, int c, int changefile, int *fnum)
* to crash. */
if (c < 0)
return posp;
- if (c > '~') /* check for islower()/isupper() */
- ;
- else if (c == '\'' || c == '`') { /* previous context mark */
- pos_copy = curwin->w_pcmark; /* need to make a copy because */
- posp = &pos_copy; /* w_pcmark may be changed soon */
- } else if (c == '"') /* to pos when leaving buffer */
+ if (c > '~') { // check for islower()/isupper()
+ } else if (c == '\'' || c == '`') { // previous context mark
+ pos_copy = curwin->w_pcmark; // need to make a copy because
+ posp = &pos_copy; // w_pcmark may be changed soon
+ } else if (c == '"') { // to pos when leaving buffer
posp = &(buf->b_last_cursor.mark);
- else if (c == '^') /* to where Insert mode stopped */
+ } else if (c == '^') { // to where Insert mode stopped
posp = &(buf->b_last_insert.mark);
- else if (c == '.') /* to where last change was made */
+ } else if (c == '.') { // to where last change was made
posp = &(buf->b_last_change.mark);
- else if (c == '[') /* to start of previous operator */
+ } else if (c == '[') { // to start of previous operator
posp = &(buf->b_op_start);
- else if (c == ']') /* to end of previous operator */
+ } else if (c == ']') { // to end of previous operator
posp = &(buf->b_op_end);
- else if (c == '{' || c == '}') { /* to previous/next paragraph */
+ } else if (c == '{' || c == '}') { // to previous/next paragraph
pos_T pos;
oparg_T oa;
int slcb = listcmd_busy;
@@ -620,9 +619,9 @@ void do_marks(exarg_T *eap)
if (arg != NULL && *arg == NUL)
arg = NULL;
- show_one_mark('\'', arg, &curwin->w_pcmark, NULL, TRUE);
+ show_one_mark('\'', arg, &curwin->w_pcmark, NULL, true);
for (i = 0; i < NMARKS; ++i)
- show_one_mark(i + 'a', arg, &curbuf->b_namedm[i].mark, NULL, TRUE);
+ show_one_mark(i + 'a', arg, &curbuf->b_namedm[i].mark, NULL, true);
for (i = 0; i < NGLOBALMARKS; ++i) {
if (namedfm[i].fmark.fnum != 0)
name = fm_getname(&namedfm[i].fmark, 15);
@@ -636,14 +635,14 @@ void do_marks(exarg_T *eap)
xfree(name);
}
}
- show_one_mark('"', arg, &curbuf->b_last_cursor.mark, NULL, TRUE);
- show_one_mark('[', arg, &curbuf->b_op_start, NULL, TRUE);
- show_one_mark(']', arg, &curbuf->b_op_end, NULL, TRUE);
- show_one_mark('^', arg, &curbuf->b_last_insert.mark, NULL, TRUE);
- show_one_mark('.', arg, &curbuf->b_last_change.mark, NULL, TRUE);
- show_one_mark('<', arg, &curbuf->b_visual.vi_start, NULL, TRUE);
- show_one_mark('>', arg, &curbuf->b_visual.vi_end, NULL, TRUE);
- show_one_mark(-1, arg, NULL, NULL, FALSE);
+ show_one_mark('"', arg, &curbuf->b_last_cursor.mark, NULL, true);
+ show_one_mark('[', arg, &curbuf->b_op_start, NULL, true);
+ show_one_mark(']', arg, &curbuf->b_op_end, NULL, true);
+ show_one_mark('^', arg, &curbuf->b_last_insert.mark, NULL, true);
+ show_one_mark('.', arg, &curbuf->b_last_change.mark, NULL, true);
+ show_one_mark('<', arg, &curbuf->b_visual.vi_start, NULL, true);
+ show_one_mark('>', arg, &curbuf->b_visual.vi_end, NULL, true);
+ show_one_mark(-1, arg, NULL, NULL, false);
}
static void
@@ -737,13 +736,14 @@ void ex_delmarks(exarg_T *eap)
from = to = *p;
for (i = from; i <= to; ++i) {
- if (lower)
+ if (lower) {
curbuf->b_namedm[i - 'a'].mark.lnum = 0;
- else {
- if (digit)
+ } else {
+ if (digit) {
n = i - '0' + NMARKS;
- else
+ } else {
n = i - 'A';
+ }
namedfm[n].fmark.mark.lnum = 0;
xfree(namedfm[n].fname);
namedfm[n].fname = NULL;
@@ -1127,10 +1127,10 @@ void cleanup_jumplist(void)
&& curwin->w_jumplist[i].fmark.mark.lnum
== curwin->w_jumplist[from].fmark.mark.lnum)
break;
- if (i >= curwin->w_jumplistlen) { // no duplicate
+ if (i >= curwin->w_jumplistlen) { // no duplicate
if (to != from) {
- // Not using curwin->w_jumplist[to++] = curwin->w_jumplist[from] because
- // this way valgrind complains about overlapping source and destination
+ // Not using curwin->w_jumplist[to++] = curwin->w_jumplist[from] because
+ // this way valgrind complains about overlapping source and destination
// in memcpy() call. (clang-3.6.0, debug build with -DEXITFREE).
curwin->w_jumplist[to] = curwin->w_jumplist[from];
}
@@ -1162,14 +1162,14 @@ void copy_jumplist(win_T *from, win_T *to)
/// Iterate over jumplist items
///
-/// @warning No jumplist-editing functions must be run while iteration is in
+/// @warning No jumplist-editing functions must be run while iteration is in
/// progress.
///
/// @param[in] iter Iterator. Pass NULL to start iteration.
/// @param[in] win Window for which jump list is processed.
/// @param[out] fm Item definition.
///
-/// @return Pointer that needs to be passed to next `mark_jumplist_iter` call or
+/// @return Pointer that needs to be passed to next `mark_jumplist_iter` call or
/// NULL if iteration is over.
const void *mark_jumplist_iter(const void *const iter, const win_T *const win,
xfmark_T *const fm)
@@ -1193,14 +1193,14 @@ const void *mark_jumplist_iter(const void *const iter, const win_T *const win,
/// Iterate over global marks
///
-/// @warning No mark-editing functions must be run while iteration is in
+/// @warning No mark-editing functions must be run while iteration is in
/// progress.
///
/// @param[in] iter Iterator. Pass NULL to start iteration.
/// @param[out] name Mark name.
/// @param[out] fm Mark definition.
///
-/// @return Pointer that needs to be passed to next `mark_global_iter` call or
+/// @return Pointer that needs to be passed to next `mark_global_iter` call or
/// NULL if iteration is over.
const void *mark_global_iter(const void *const iter, char *const name,
xfmark_T *const fm)
@@ -1234,11 +1234,11 @@ const void *mark_global_iter(const void *const iter, char *const name,
/// Get next mark and its name
///
/// @param[in] buf Buffer for which next mark is taken.
-/// @param[in,out] mark_name Pointer to the current mark name. Next mark name
+/// @param[in,out] mark_name Pointer to the current mark name. Next mark name
/// will be saved at this address as well.
///
-/// Current mark name must either be NUL, '"', '^',
-/// '.' or 'a' .. 'z'. If it is neither of these
+/// Current mark name must either be NUL, '"', '^',
+/// '.' or 'a' .. 'z'. If it is neither of these
/// behaviour is undefined.
///
/// @return Pointer to the next mark or NULL.
@@ -1275,7 +1275,7 @@ static inline const fmark_T *next_buffer_mark(const buf_T *const buf,
/// Iterate over buffer marks
///
-/// @warning No mark-editing functions must be run while iteration is in
+/// @warning No mark-editing functions must be run while iteration is in
/// progress.
///
/// @param[in] iter Iterator. Pass NULL to start iteration.
@@ -1283,7 +1283,7 @@ static inline const fmark_T *next_buffer_mark(const buf_T *const buf,
/// @param[out] name Mark name.
/// @param[out] fm Mark definition.
///
-/// @return Pointer that needs to be passed to next `mark_buffer_iter` call or
+/// @return Pointer that needs to be passed to next `mark_buffer_iter` call or
/// NULL if iteration is over.
const void *mark_buffer_iter(const void *const iter, const buf_T *const buf,
char *const name, fmark_T *const fm)
@@ -1321,7 +1321,7 @@ const void *mark_buffer_iter(const void *const iter, const buf_T *const buf,
///
/// @param[in] name Mark name.
/// @param[in] fm Mark to be set.
-/// @param[in] update If true then only set global mark if it was created
+/// @param[in] update If true then only set global mark if it was created
/// later then existing one.
///
/// @return true on success, false on failure.
@@ -1347,7 +1347,7 @@ bool mark_set_global(const char name, const xfmark_T fm, const bool update)
/// @param[in] name Mark name.
/// @param[in] buf Pointer to the buffer to set mark in.
/// @param[in] fm Mark to be set.
-/// @param[in] update If true then only set global mark if it was created
+/// @param[in] update If true then only set global mark if it was created
/// later then existing one.
///
/// @return true on success, false on failure.
diff --git a/src/nvim/mark_defs.h b/src/nvim/mark_defs.h
index 8f8425f0a6..720b2475ed 100644
--- a/src/nvim/mark_defs.h
+++ b/src/nvim/mark_defs.h
@@ -21,7 +21,7 @@
/// Total possible number of local marks
///
-/// That are uppercase marks plus '"', '^' and '.'. There are other local marks,
+/// That are uppercase marks plus '"', '^' and '.'. There are other local marks,
/// but they are not saved in ShaDa files.
#define NLOCALMARKS (NMARKS + 3)
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index d59630697d..3fd2c0b773 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -5190,7 +5190,7 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet)
reg->y_size = lines->lv_len;
reg->additional_data = NULL;
reg->timestamp = 0;
- // Timestamp is not saved for clipboard registers because clipboard registers
+ // Timestamp is not saved for clipboard registers because clipboard registers
// are not saved in the ShaDa file.
int i = 0;
@@ -5327,7 +5327,7 @@ static inline bool reg_empty(const yankreg_T *const reg)
/// @param[out] name Register name.
/// @param[out] reg Register contents.
///
-/// @return Pointer that needs to be passed to next `op_register_iter` call or
+/// @return Pointer that needs to be passed to next `op_register_iter` call or
/// NULL if iteration is over.
const void *op_register_iter(const void *const iter, char *const name,
yankreg_T *const reg)
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 3f90293e19..653b217485 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -2441,9 +2441,8 @@ did_set_string_option (
verbose_stop();
if (*p_vfile != NUL && verbose_open() == FAIL)
errmsg = e_invarg;
- }
/* 'shada' */
- else if (varp == &p_shada) {
+ } else if (varp == &p_shada) {
for (s = p_shada; *s; ) {
/* Check it's a valid character */
if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL) {
diff --git a/src/nvim/search.c b/src/nvim/search.c
index 3fbddc7fc8..8ba888841c 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -4633,7 +4633,7 @@ void set_substitute_pattern(const SearchPattern pat)
/// Set last used search pattern
///
-/// @param[in] is_substitute_pattern If true set substitute pattern as last
+/// @param[in] is_substitute_pattern If true set substitute pattern as last
/// used. Otherwise sets search pattern.
void set_last_used_pattern(const bool is_substitute_pattern)
{
diff --git a/src/nvim/search.h b/src/nvim/search.h
index 1fc2d6710e..6947f79d49 100644
--- a/src/nvim/search.h
+++ b/src/nvim/search.h
@@ -44,7 +44,7 @@
/// Structure containing offset definition for the last search pattern
///
-/// @note Only offset for the last search pattern is used, not for the last
+/// @note Only offset for the last search pattern is used, not for the last
/// substitute pattern.
typedef struct soffset {
char dir; ///< Search direction: forward ('/') or backward ('?')