diff options
author | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2014-12-13 11:10:19 -0300 |
---|---|---|
committer | Felipe Oliveira Carvalho <felipekde@gmail.com> | 2014-12-18 15:41:37 -0300 |
commit | 3c857900fe9a7eff87aa4fbe6e7b80ba602ad2bd (patch) | |
tree | 01a9c192b058d769e4b2422cba8930a7f67a0cab /src/nvim/regexp.c | |
parent | bd19cc4f8fc3d02a030caba911a1af008585f688 (diff) | |
download | rneovim-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/regexp.c')
-rw-r--r-- | src/nvim/regexp.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 69c2119697..dd7af63ce0 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -602,7 +602,7 @@ static int get_char_class(char_u **pp) int i; if ((*pp)[1] == ':') { - for (i = 0; i < (int)(sizeof(class_names) / sizeof(*class_names)); ++i) + for (i = 0; i < (int)ARRAY_SIZE(class_names); ++i) if (STRNCMP(*pp + 2, class_names[i], STRLEN(class_names[i])) == 0) { *pp += STRLEN(class_names[i]) + 2; return i; |