diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2023-01-10 20:21:51 +0100 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2023-01-11 19:42:27 +0100 |
commit | 3722a1e0001cd52d2b2b8f1b9a40917783d499f9 (patch) | |
tree | d51440f119e1fbfde0b849a821a1a075660e3f4a | |
parent | 162f778afe6af58b06132c41fb010309d2f935ec (diff) | |
download | ccache-3722a1e0001cd52d2b2b8f1b9a40917783d499f9.tar.gz |
refactor: Use std::size to compute array size
-rw-r--r-- | src/compopt.cpp | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/compopt.cpp b/src/compopt.cpp index 867d8c4d..e5415fac 100644 --- a/src/compopt.cpp +++ b/src/compopt.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2010-2022 Joel Rosdahl and other contributors +// Copyright (C) 2010-2023 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -45,8 +45,6 @@ // The option only affects compilation; not passed to the preprocessor. #define AFFECTS_COMP (1 << 6) -#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) - struct CompOpt { const char* name; @@ -179,11 +177,8 @@ find(const std::string& option) { CompOpt key; key.name = option.c_str(); - void* result = bsearch(&key, - compopts, - ARRAY_SIZE(compopts), - sizeof(compopts[0]), - compare_compopts); + void* result = bsearch( + &key, compopts, std::size(compopts), sizeof(compopts[0]), compare_compopts); return static_cast<CompOpt*>(result); } @@ -194,7 +189,7 @@ find_prefix(const std::string& option) key.name = option.c_str(); void* result = bsearch(&key, compopts, - ARRAY_SIZE(compopts), + std::size(compopts), sizeof(compopts[0]), compare_prefix_compopts); return static_cast<CompOpt*>(result); @@ -207,7 +202,7 @@ bool compopt_verify_sortedness_and_flags(); bool compopt_verify_sortedness_and_flags() { - for (size_t i = 0; i < ARRAY_SIZE(compopts); i++) { + for (size_t i = 0; i < std::size(compopts); ++i) { if (compopts[i].type & TOO_HARD && compopts[i].type & TAKES_CONCAT_ARG) { PRINT(stderr, "type (TOO_HARD | TAKES_CONCAT_ARG) not allowed, used by {}\n", |