aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/option.c
diff options
context:
space:
mode:
authorFelipe Oliveira Carvalho <felipekde@gmail.com>2014-12-13 11:10:19 -0300
committerFelipe Oliveira Carvalho <felipekde@gmail.com>2014-12-18 15:41:37 -0300
commit3c857900fe9a7eff87aa4fbe6e7b80ba602ad2bd (patch)
tree01a9c192b058d769e4b2422cba8930a7f67a0cab /src/nvim/option.c
parentbd19cc4f8fc3d02a030caba911a1af008585f688 (diff)
downloadrneovim-3c857900fe9a7eff87aa4fbe6e7b80ba602ad2bd.tar.gz
rneovim-3c857900fe9a7eff87aa4fbe6e7b80ba602ad2bd.tar.bz2
rneovim-3c857900fe9a7eff87aa4fbe6e7b80ba602ad2bd.zip
Define and use the ARRAY_SIZE macro
A similar macro is defined in the Linux kernel [1]. To refactor the code I used a slightly modified Coccinelle script I found in [2]. ```diff // Use the macro ARRAY_SIZE when possible // // Confidence: High // Copyright: (C) Gilles Muller, Julia Lawall, EMN, DIKU. GPLv2. // URL: http://www.emn.fr/x-info/coccinelle/rules/array.html // Options: -I ... -all_includes can give more complete results @@ type T; T[] E; @@ - (sizeof(E)/sizeof(*E)) + ARRAY_SIZE(E) @@ type T; T[] E; @@ - (sizeof(E)/sizeof(E[...])) + ARRAY_SIZE(E) @@ type T; T[] E; @@ - (sizeof(E)/sizeof(T)) + ARRAY_SIZE(E) @n@ identifier AS,E; @@ - #define AS(E) ARRAY_SIZE(E) @@ expression E; identifier n.AS; @@ - AS(E) + ARRAY_SIZE(E) ``` `spatch --in-place --sp-file array_size.cocci -I src/ -I build/include/ -I build/src/nvim/auto/ src/nvim/*.c` [1] http://lxr.free-electrons.com/source/include/linux/kernel.h#L54 [2] http://www.emn.fr/z-info/coccinelle/rules/#macros
Diffstat (limited to 'src/nvim/option.c')
-rw-r--r--src/nvim/option.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 2b3c87511e..fe2c756c01 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -1883,7 +1883,7 @@ void set_init_1(void)
int mustfree;
ga_init(&ga, 1, 100);
- for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n) {
+ for (n = 0; n < (long)ARRAY_SIZE(names); ++n) {
mustfree = FALSE;
# ifdef UNIX
if (*names[n] == NUL)
@@ -4723,10 +4723,10 @@ static char_u *set_chars_option(char_u **varp)
if (varp == &p_lcs) {
tab = lcstab;
- entries = sizeof(lcstab) / sizeof(struct charstab);
+ entries = ARRAY_SIZE(lcstab);
} else {
tab = filltab;
- entries = sizeof(filltab) / sizeof(struct charstab);
+ entries = ARRAY_SIZE(filltab);
}
/* first round: check for valid value, second round: assign values */
@@ -7250,7 +7250,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***
for (loop = 0; loop <= 1; ++loop) {
regmatch->rm_ic = ic;
if (xp->xp_context != EXPAND_BOOL_SETTINGS) {
- for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
+ for (match = 0; match < (int)ARRAY_SIZE(names);
++match)
if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0)) {
if (loop == 0)