Remove unnecessary ARRAY_SIZE macros.
Use the canonical one instead.
Change-Id: Id80f19455f37fd2a29d9ec4191c1a0af80c5c0e7
diff --git a/adb/adb.cpp b/adb/adb.cpp
index c3f1a96..725aa91 100644
--- a/adb/adb.cpp
+++ b/adb/adb.cpp
@@ -46,8 +46,6 @@
#include "adb_utils.h"
#include "transport.h"
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
-
#if !ADB_HOST
#include <cutils/properties.h>
#include <sys/capability.h>
diff --git a/fastboot/engine.cpp b/fastboot/engine.cpp
index a245e49..728dcb8 100644
--- a/fastboot/engine.cpp
+++ b/fastboot/engine.cpp
@@ -38,8 +38,6 @@
#include <sys/types.h>
#include <unistd.h>
-#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
-
#define OP_DOWNLOAD 1
#define OP_COMMAND 2
#define OP_QUERY 3
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index 1839d25..665b9d0 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -47,6 +47,7 @@
#include <utility>
#include <vector>
+#include <android-base/macros.h>
#include <android-base/parseint.h>
#include <android-base/parsenetaddress.h>
#include <android-base/stringprintf.h>
@@ -67,8 +68,6 @@
#define O_BINARY 0
#endif
-#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*(a)))
-
char cur_product[FB_RESPONSE_SZ + 1];
static const char* serial = nullptr;
@@ -926,7 +925,7 @@
setup_requirements(reinterpret_cast<char*>(data), sz);
- for (size_t i = 0; i < ARRAY_SIZE(images); ++i) {
+ for (size_t i = 0; i < arraysize(images); ++i) {
int fd = unzip_to_file(zip, images[i].img_name);
if (fd == -1) {
if (images[i].is_optional) {
@@ -988,7 +987,7 @@
setup_requirements(reinterpret_cast<char*>(data), sz);
- for (size_t i = 0; i < ARRAY_SIZE(images); i++) {
+ for (size_t i = 0; i < arraysize(images); i++) {
fname = find_item(images[i].part_name, product);
fastboot_buffer buf;
if (!load_buf(transport, fname.c_str(), &buf)) {
diff --git a/libcutils/tests/PropertiesTest.cpp b/libcutils/tests/PropertiesTest.cpp
index 5f2396b..f66590b 100644
--- a/libcutils/tests/PropertiesTest.cpp
+++ b/libcutils/tests/PropertiesTest.cpp
@@ -24,11 +24,12 @@
#include <sstream>
#include <iostream>
+#include <android-base/macros.h>
+
namespace android {
#define STRINGIFY_INNER(x) #x
#define STRINGIFY(x) STRINGIFY_INNER(x)
-#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
#define ASSERT_OK(x) ASSERT_EQ(0, (x))
#define EXPECT_OK(x) EXPECT_EQ(0, (x))
@@ -85,7 +86,7 @@
}
void ResetValue(unsigned char c = 0xFF) {
- for (size_t i = 0; i < ARRAY_SIZE(mValue); ++i) {
+ for (size_t i = 0; i < arraysize(mValue); ++i) {
mValue[i] = (char) c;
}
}
@@ -177,7 +178,7 @@
* TRUE
*/
const char *valuesTrue[] = { "1", "true", "y", "yes", "on", };
- for (size_t i = 0; i < ARRAY_SIZE(valuesTrue); ++i) {
+ for (size_t i = 0; i < arraysize(valuesTrue); ++i) {
ASSERT_OK(property_set(PROPERTY_TEST_KEY, valuesTrue[i]));
bool val = property_get_bool(PROPERTY_TEST_KEY, /*default_value*/false);
EXPECT_TRUE(val) << "Property should've been TRUE for value: '" << valuesTrue[i] << "'";
@@ -187,7 +188,7 @@
* FALSE
*/
const char *valuesFalse[] = { "0", "false", "n", "no", "off", };
- for (size_t i = 0; i < ARRAY_SIZE(valuesFalse); ++i) {
+ for (size_t i = 0; i < arraysize(valuesFalse); ++i) {
ASSERT_OK(property_set(PROPERTY_TEST_KEY, valuesFalse[i]));
bool val = property_get_bool(PROPERTY_TEST_KEY, /*default_value*/true);
EXPECT_FALSE(val) << "Property shoud've been FALSE For string value: '" << valuesFalse[i] << "'";
@@ -200,7 +201,7 @@
"+1", " 1 ", " true", " true ", " y ", " yes", "yes ",
"+0", "-0", "00", " 00 ", " false", "false ",
};
- for (size_t i = 0; i < ARRAY_SIZE(valuesNeither); ++i) {
+ for (size_t i = 0; i < arraysize(valuesNeither); ++i) {
ASSERT_OK(property_set(PROPERTY_TEST_KEY, valuesNeither[i]));
// The default value should always be used
@@ -249,9 +250,9 @@
DEFAULT_VALUE, DEFAULT_VALUE,
};
- ASSERT_EQ(ARRAY_SIZE(setValues), ARRAY_SIZE(getValues));
+ ASSERT_EQ(arraysize(setValues), arraysize(getValues));
- for (size_t i = 0; i < ARRAY_SIZE(setValues); ++i) {
+ for (size_t i = 0; i < arraysize(setValues); ++i) {
ASSERT_OK(property_set(PROPERTY_TEST_KEY, setValues[i]));
int64_t val = property_get_int64(PROPERTY_TEST_KEY, DEFAULT_VALUE);
@@ -296,9 +297,9 @@
DEFAULT_VALUE, DEFAULT_VALUE,
};
- ASSERT_EQ(ARRAY_SIZE(setValues), ARRAY_SIZE(getValues));
+ ASSERT_EQ(arraysize(setValues), arraysize(getValues));
- for (size_t i = 0; i < ARRAY_SIZE(setValues); ++i) {
+ for (size_t i = 0; i < arraysize(setValues); ++i) {
ASSERT_OK(property_set(PROPERTY_TEST_KEY, setValues[i]));
int32_t val = property_get_int32(PROPERTY_TEST_KEY, DEFAULT_VALUE);
diff --git a/libmemunreachable/Allocator.cpp b/libmemunreachable/Allocator.cpp
index 68f654c..6fe67a4 100644
--- a/libmemunreachable/Allocator.cpp
+++ b/libmemunreachable/Allocator.cpp
@@ -52,8 +52,6 @@
return (x + y - 1) / y;
}
-#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
-
static constexpr size_t kPageSize = 4096;
static constexpr size_t kChunkSize = 256 * 1024;
static constexpr size_t kUsableChunkSize = kChunkSize - kPageSize;
@@ -258,7 +256,7 @@
unsigned int i = first_free_bitmap_;
while (free_bitmap_[i] == 0)
i++;
- assert(i < ARRAY_SIZE(free_bitmap_));
+ assert(i < arraysize(free_bitmap_));
unsigned int bit = __builtin_ffs(free_bitmap_[i]) - 1;
assert(free_bitmap_[i] & (1U << bit));
free_bitmap_[i] &= ~(1U << bit);
@@ -266,7 +264,7 @@
assert(n < max_allocations_);
unsigned int page = n * allocation_size_ / kPageSize;
- assert(page / 32 < ARRAY_SIZE(dirty_pages_));
+ assert(page / 32 < arraysize(dirty_pages_));
dirty_pages_[page / 32] |= 1U << (page % 32);
free_count_--;
@@ -285,7 +283,7 @@
unsigned int i = n / 32;
unsigned int bit = n % 32;
- assert(i < ARRAY_SIZE(free_bitmap_));
+ assert(i < arraysize(free_bitmap_));
assert(!(free_bitmap_[i] & (1U << bit)));
free_bitmap_[i] |= 1U << bit;
free_count_++;