mirror of
https://github.com/neovim/neovim.git
synced 2025-10-01 07:28:34 +00:00
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
This commit is contained in:
@@ -986,7 +986,7 @@ void intro_message(int colon)
|
||||
};
|
||||
|
||||
// blanklines = screen height - # message lines
|
||||
blanklines = (int)Rows - ((sizeof(lines) / sizeof(char *)) - 1);
|
||||
blanklines = (int)Rows - (ARRAY_SIZE(lines) - 1);
|
||||
|
||||
// Don't overwrite a statusline. Depends on 'cmdheight'.
|
||||
if (p_ls > 1) {
|
||||
@@ -1006,7 +1006,7 @@ void intro_message(int colon)
|
||||
row = blanklines / 2;
|
||||
|
||||
if (((row >= 2) && (Columns >= 50)) || colon) {
|
||||
for (i = 0; i < (int)(sizeof(lines) / sizeof(char *)); ++i) {
|
||||
for (i = 0; i < (int)ARRAY_SIZE(lines); ++i) {
|
||||
p = lines[i];
|
||||
|
||||
if (sponsor != 0) {
|
||||
|
Reference in New Issue
Block a user