]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: Use ARRAY_SIZE macro
authorsimransinghal <singhalsimran0@gmail.com>
Tue, 20 Mar 2018 20:19:35 +0000 (01:49 +0530)
committersimransinghal <singhalsimran0@gmail.com>
Thu, 12 Apr 2018 08:57:46 +0000 (14:27 +0530)
Use ARRAY_SIZE macro instead of sizeof(x)/sizeof(x[0]) to improve code readability.
Defined it in appropriate header file.

Signed-off-by: Simran Singhal <singhalsimran0@gmail.com>
src/common/entity_name.cc
src/common/entity_name.h
src/common/utf8.c
src/common/utf8.h

index 7c9cd78485824345e0702ab0820022e27b891d34..918361604423c6c5ab9b7e46ca759ad57dacb355 100644 (file)
@@ -168,7 +168,7 @@ std::ostream& operator<<(std::ostream& out, const EntityName& n)
 uint32_t str_to_ceph_entity_type(const char * str)
 {
   size_t i;
-  for (i = 0; i < sizeof(STR_TO_ENTITY_TYPE)/sizeof(STR_TO_ENTITY_TYPE[0]); ++i) {
+  for (i = 0; i < ARRAY_SIZE(STR_TO_ENTITY_TYPE); ++i) {
     if (strcmp(str, STR_TO_ENTITY_TYPE[i].str) == 0)
       return STR_TO_ENTITY_TYPE[i].type;
   }
index 44edebb04863efbed0401c0dae9caa2876c21e73..ea4125c5fb0303943a837ee53ffa793d0c92a121 100644 (file)
@@ -19,6 +19,8 @@
 
 #include "msg/msg_types.h"
 
+#define ARRAY_SIZE(a)   (sizeof(a) / sizeof(*a))
+
 /* Represents a Ceph entity name.
  *
  * For example, mds.0 is the name of the first metadata server.
index 5a8592f1cc5e2afbea9ef52b5b49c8674ca01ed0..d8663aee57d0f1a52f87faef83714380cbf89804 100644 (file)
@@ -38,7 +38,7 @@ int encode_utf8(unsigned long u, unsigned char *buf)
                0x0000007ful, 0x000007fful, 0x0000fffful,
                0x001ffffful, 0x03fffffful, 0x7ffffffful
        };
-       static const int MAX_VAL_SZ = sizeof(max_val) / sizeof(max_val[0]);
+       static const int MAX_VAL_SZ = ARRAY_SIZE(max_val);
 
        for (i = 0; i < MAX_VAL_SZ; ++i) {
                if (u <= max_val[i])
index 83efe6fd6dad43c81e417208102c39f15e75dba6..cf8daeed1786af6f1aa7629b7d172f0bcf796182 100644 (file)
@@ -17,6 +17,7 @@
 
 #define MAX_UTF8_SZ 6
 #define INVALID_UTF8_CHAR 0xfffffffful
+#define ARRAY_SIZE(a)   (sizeof(a) / sizeof(*a))
 
 #ifdef __cplusplus
 extern "C" {