From: Joel Rosdahl Date: Tue, 10 Jan 2023 19:21:51 +0000 (+0100) Subject: refactor: Use std::size to compute array size X-Git-Tag: v4.8~66 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3722a1e0001cd52d2b2b8f1b9a40917783d499f9;p=thirdparty%2Fccache.git refactor: Use std::size to compute array size --- diff --git a/src/compopt.cpp b/src/compopt.cpp index 867d8c4d1..e5415fac5 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(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(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",