aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/syntax.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/syntax.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/syntax.c')
-rw-r--r--src/nvim/syntax.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index 3deda0a8c9..6787ca8080 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -3943,7 +3943,7 @@ get_syn_options (
if (strchr(first_letters, *arg) == NULL)
break;
- for (fidx = sizeof(flagtab) / sizeof(struct flag); --fidx >= 0; ) {
+ for (fidx = ARRAY_SIZE(flagtab); --fidx >= 0; ) {
p = flagtab[fidx].name;
int i;
for (i = 0, len = 0; p[i] != NUL; i += 2, ++len)
@@ -6295,7 +6295,7 @@ do_highlight (
attr = 0;
off = 0;
while (arg[off] != NUL) {
- for (i = sizeof(hl_attr_table) / sizeof(int); --i >= 0; ) {
+ for (i = ARRAY_SIZE(hl_attr_table); --i >= 0; ) {
len = (int)STRLEN(hl_name_table[i]);
if (STRNICMP(arg + off, hl_name_table[i], len) == 0) {
attr |= hl_attr_table[i];
@@ -6416,7 +6416,7 @@ do_highlight (
/* reduce calls to STRICMP a bit, it can be slow */
off = TOUPPER_ASC(*arg);
- for (i = (sizeof(color_names) / sizeof(char *)); --i >= 0; )
+ for (i = ARRAY_SIZE(color_names); --i >= 0; )
if (off == color_names[i][0]
&& STRICMP(arg + 1, color_names[i] + 1) == 0)
break;