Skip to content

Commit

Permalink
Use base::size rather than arraysize in base/.
Browse files Browse the repository at this point in the history
This is purely a mechanical change; there is no intended behavior change.

BUG=837308

Change-Id: Id02b2c0bf9efcbdbefe2f8a3278bca90d167a85d
Reviewed-on: https://chromium-review.googlesource.com/c/1390906
Reviewed-by: Robert Sesek <rsesek@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
Reviewed-by: Jungshik Shin <jshin@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#620036}
  • Loading branch information
Avi Drissman authored and Commit Bot committed Jan 4, 2019
1 parent 17b3775 commit e3b70bf
Show file tree
Hide file tree
Showing 78 changed files with 371 additions and 369 deletions.
28 changes: 14 additions & 14 deletions base/android/jni_array_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

#include "base/android/jni_android.h"
#include "base/android/scoped_java_ref.h"
#include "base/macros.h"
#include "base/stl_util.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace base {
namespace android {

TEST(JniArray, BasicConversions) {
const uint8_t kBytes[] = {0, 1, 2, 3};
const size_t kLen = arraysize(kBytes);
const size_t kLen = base::size(kBytes);
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jbyteArray> bytes = ToJavaByteArray(env, kBytes, kLen);
ASSERT_TRUE(bytes);
Expand Down Expand Up @@ -75,7 +75,7 @@ void CheckBoolConversion(JNIEnv* env,

TEST(JniArray, BoolConversions) {
const bool kBools[] = {false, true, false};
const size_t kLen = arraysize(kBools);
const size_t kLen = base::size(kBools);

JNIEnv* env = AttachCurrentThread();
CheckBoolConversion(env, kBools, kLen, ToJavaBooleanArray(env, kBools, kLen));
Expand All @@ -101,7 +101,7 @@ void CheckIntConversion(
TEST(JniArray, IntConversions) {
const int kInts[] = {0, 1, -1, std::numeric_limits<int32_t>::min(),
std::numeric_limits<int32_t>::max()};
const size_t kLen = arraysize(kInts);
const size_t kLen = base::size(kInts);

JNIEnv* env = AttachCurrentThread();
CheckIntConversion(env, kInts, kLen, ToJavaIntArray(env, kInts, kLen));
Expand Down Expand Up @@ -129,7 +129,7 @@ void CheckLongConversion(JNIEnv* env,
TEST(JniArray, LongConversions) {
const int64_t kLongs[] = {0, 1, -1, std::numeric_limits<int64_t>::min(),
std::numeric_limits<int64_t>::max()};
const size_t kLen = arraysize(kLongs);
const size_t kLen = base::size(kLongs);

JNIEnv* env = AttachCurrentThread();
CheckLongConversion(env, kLongs, kLen, ToJavaLongArray(env, kLongs, kLen));
Expand Down Expand Up @@ -179,7 +179,7 @@ void CheckFloatConversion(

TEST(JniArray, FloatConversions) {
const float kFloats[] = { 0.0f, 1.0f, -10.0f};
const size_t kLen = arraysize(kFloats);
const size_t kLen = base::size(kFloats);

JNIEnv* env = AttachCurrentThread();
CheckFloatConversion(env, kFloats, kLen,
Expand All @@ -191,7 +191,7 @@ TEST(JniArray, FloatConversions) {

TEST(JniArray, JavaBooleanArrayToBoolVector) {
const bool kBools[] = {false, true, false};
const size_t kLen = arraysize(kBools);
const size_t kLen = base::size(kBools);

JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jbooleanArray> jbooleans(env, env->NewBooleanArray(kLen));
Expand All @@ -214,7 +214,7 @@ TEST(JniArray, JavaBooleanArrayToBoolVector) {

TEST(JniArray, JavaIntArrayToIntVector) {
const int kInts[] = {0, 1, -1};
const size_t kLen = arraysize(kInts);
const size_t kLen = base::size(kInts);

JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jintArray> jints(env, env->NewIntArray(kLen));
Expand All @@ -236,7 +236,7 @@ TEST(JniArray, JavaIntArrayToIntVector) {

TEST(JniArray, JavaLongArrayToInt64Vector) {
const int64_t kInt64s[] = {0LL, 1LL, -1LL};
const size_t kLen = arraysize(kInt64s);
const size_t kLen = base::size(kInt64s);

JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jlongArray> jlongs(env, env->NewLongArray(kLen));
Expand Down Expand Up @@ -264,7 +264,7 @@ TEST(JniArray, JavaLongArrayToInt64Vector) {

TEST(JniArray, JavaLongArrayToLongVector) {
const int64_t kInt64s[] = {0LL, 1LL, -1LL};
const size_t kLen = arraysize(kInt64s);
const size_t kLen = base::size(kInt64s);

JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jlongArray> jlongs(env, env->NewLongArray(kLen));
Expand All @@ -291,7 +291,7 @@ TEST(JniArray, JavaLongArrayToLongVector) {

TEST(JniArray, JavaFloatArrayToFloatVector) {
const float kFloats[] = {0.0, 0.5, -0.5};
const size_t kLen = arraysize(kFloats);
const size_t kLen = base::size(kFloats);

JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jfloatArray> jfloats(env, env->NewFloatArray(kLen));
Expand Down Expand Up @@ -367,12 +367,12 @@ TEST(JniArray, JavaArrayOfIntArrayToIntVector) {
// Populate int[][] object.
const int kInts0[] = {0, 1, -1, std::numeric_limits<int32_t>::min(),
std::numeric_limits<int32_t>::max()};
const size_t kLen0 = arraysize(kInts0);
const size_t kLen0 = base::size(kInts0);
ScopedJavaLocalRef<jintArray> int_array0 = ToJavaIntArray(env, kInts0, kLen0);
env->SetObjectArrayElement(array.obj(), 0, int_array0.obj());

const int kInts1[] = {3, 4, 5};
const size_t kLen1 = arraysize(kInts1);
const size_t kLen1 = base::size(kInts1);
ScopedJavaLocalRef<jintArray> int_array1 = ToJavaIntArray(env, kInts1, kLen1);
env->SetObjectArrayElement(array.obj(), 1, int_array1.obj());

Expand All @@ -382,7 +382,7 @@ TEST(JniArray, JavaArrayOfIntArrayToIntVector) {
env->SetObjectArrayElement(array.obj(), 2, int_array2.obj());

const int kInts3[] = {16};
const size_t kLen3 = arraysize(kInts3);
const size_t kLen3 = base::size(kInts3);
ScopedJavaLocalRef<jintArray> int_array3 = ToJavaIntArray(env, kInts3, kLen3);
env->SetObjectArrayElement(array.obj(), 3, int_array3.obj());

Expand Down
7 changes: 3 additions & 4 deletions base/command_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/stl_util.h"
#include "base/strings/string_split.h"
#include "base/strings/string_tokenizer.h"
Expand Down Expand Up @@ -42,7 +41,7 @@ const CommandLine::CharType* const kSwitchPrefixes[] = {L"--", L"-", L"/"};
// Unixes don't use slash as a switch.
const CommandLine::CharType* const kSwitchPrefixes[] = {"--", "-"};
#endif
size_t switch_prefix_count = arraysize(kSwitchPrefixes);
size_t switch_prefix_count = base::size(kSwitchPrefixes);

size_t GetSwitchPrefixLength(const CommandLine::StringType& string) {
for (size_t i = 0; i < switch_prefix_count; ++i) {
Expand Down Expand Up @@ -186,8 +185,8 @@ CommandLine::~CommandLine() = default;
// static
void CommandLine::set_slash_is_not_a_switch() {
// The last switch prefix should be slash, so adjust the size to skip it.
DCHECK_EQ(wcscmp(kSwitchPrefixes[arraysize(kSwitchPrefixes) - 1], L"/"), 0);
switch_prefix_count = arraysize(kSwitchPrefixes) - 1;
DCHECK_EQ(wcscmp(kSwitchPrefixes[base::size(kSwitchPrefixes) - 1], L"/"), 0);
switch_prefix_count = base::size(kSwitchPrefixes) - 1;
}

// static
Expand Down
36 changes: 18 additions & 18 deletions base/command_line_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <vector>

#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand Down Expand Up @@ -47,7 +47,7 @@ TEST(CommandLineTest, CommandLineConstructor) {
FILE_PATH_LITERAL("--not-a-switch"),
FILE_PATH_LITERAL("\"in the time of submarines...\""),
FILE_PATH_LITERAL("unquoted arg-with-space")};
CommandLine cl(arraysize(argv), argv);
CommandLine cl(base::size(argv), argv);

EXPECT_FALSE(cl.GetCommandLineString().empty());
EXPECT_FALSE(cl.HasSwitch("cruller"));
Expand Down Expand Up @@ -307,22 +307,22 @@ TEST(CommandLineTest, AppendSwitchesDashDash) {
const CommandLine::CharType* raw_argv[] = { FILE_PATH_LITERAL("prog"),
FILE_PATH_LITERAL("--"),
FILE_PATH_LITERAL("--arg1") };
CommandLine cl(arraysize(raw_argv), raw_argv);

cl.AppendSwitch("switch1");
cl.AppendSwitchASCII("switch2", "foo");

cl.AppendArg("--arg2");

EXPECT_EQ(FILE_PATH_LITERAL("prog --switch1 --switch2=foo -- --arg1 --arg2"),
cl.GetCommandLineString());
CommandLine::StringVector cl_argv = cl.argv();
EXPECT_EQ(FILE_PATH_LITERAL("prog"), cl_argv[0]);
EXPECT_EQ(FILE_PATH_LITERAL("--switch1"), cl_argv[1]);
EXPECT_EQ(FILE_PATH_LITERAL("--switch2=foo"), cl_argv[2]);
EXPECT_EQ(FILE_PATH_LITERAL("--"), cl_argv[3]);
EXPECT_EQ(FILE_PATH_LITERAL("--arg1"), cl_argv[4]);
EXPECT_EQ(FILE_PATH_LITERAL("--arg2"), cl_argv[5]);
CommandLine cl(base::size(raw_argv), raw_argv);

cl.AppendSwitch("switch1");
cl.AppendSwitchASCII("switch2", "foo");

cl.AppendArg("--arg2");

EXPECT_EQ(FILE_PATH_LITERAL("prog --switch1 --switch2=foo -- --arg1 --arg2"),
cl.GetCommandLineString());
CommandLine::StringVector cl_argv = cl.argv();
EXPECT_EQ(FILE_PATH_LITERAL("prog"), cl_argv[0]);
EXPECT_EQ(FILE_PATH_LITERAL("--switch1"), cl_argv[1]);
EXPECT_EQ(FILE_PATH_LITERAL("--switch2=foo"), cl_argv[2]);
EXPECT_EQ(FILE_PATH_LITERAL("--"), cl_argv[3]);
EXPECT_EQ(FILE_PATH_LITERAL("--arg1"), cl_argv[4]);
EXPECT_EQ(FILE_PATH_LITERAL("--arg2"), cl_argv[5]);
}

// Tests that when AppendArguments is called that the program is set correctly
Expand Down
30 changes: 15 additions & 15 deletions base/containers/linked_list_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// found in the LICENSE file.

#include "base/containers/linked_list.h"
#include "base/macros.h"
#include "base/stl_util.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace base {
Expand Down Expand Up @@ -91,7 +91,7 @@ TEST(LinkedList, Append) {
EXPECT_EQ(&n1, list.tail());
{
const int expected[] = {1};
ExpectListContents(list, arraysize(expected), expected);
ExpectListContents(list, base::size(expected), expected);
}

Node n2(2);
Expand All @@ -101,7 +101,7 @@ TEST(LinkedList, Append) {
EXPECT_EQ(&n2, list.tail());
{
const int expected[] = {1, 2};
ExpectListContents(list, arraysize(expected), expected);
ExpectListContents(list, base::size(expected), expected);
}

Node n3(3);
Expand All @@ -111,7 +111,7 @@ TEST(LinkedList, Append) {
EXPECT_EQ(&n3, list.tail());
{
const int expected[] = {1, 2, 3};
ExpectListContents(list, arraysize(expected), expected);
ExpectListContents(list, base::size(expected), expected);
}
}

Expand All @@ -134,7 +134,7 @@ TEST(LinkedList, RemoveFromList) {
EXPECT_EQ(&n5, list.tail());
{
const int expected[] = {1, 2, 3, 4, 5};
ExpectListContents(list, arraysize(expected), expected);
ExpectListContents(list, base::size(expected), expected);
}

// Remove from the middle.
Expand All @@ -144,7 +144,7 @@ TEST(LinkedList, RemoveFromList) {
EXPECT_EQ(&n5, list.tail());
{
const int expected[] = {1, 2, 4, 5};
ExpectListContents(list, arraysize(expected), expected);
ExpectListContents(list, base::size(expected), expected);
}

// Remove from the tail.
Expand All @@ -154,7 +154,7 @@ TEST(LinkedList, RemoveFromList) {
EXPECT_EQ(&n4, list.tail());
{
const int expected[] = {1, 2, 4};
ExpectListContents(list, arraysize(expected), expected);
ExpectListContents(list, base::size(expected), expected);
}

// Remove from the head.
Expand All @@ -164,7 +164,7 @@ TEST(LinkedList, RemoveFromList) {
EXPECT_EQ(&n4, list.tail());
{
const int expected[] = {2, 4};
ExpectListContents(list, arraysize(expected), expected);
ExpectListContents(list, base::size(expected), expected);
}

// Empty the list.
Expand All @@ -186,7 +186,7 @@ TEST(LinkedList, RemoveFromList) {
EXPECT_EQ(&n5, list.tail());
{
const int expected[] = {1, 2, 3, 4, 5};
ExpectListContents(list, arraysize(expected), expected);
ExpectListContents(list, base::size(expected), expected);
}
}

Expand All @@ -205,7 +205,7 @@ TEST(LinkedList, InsertBefore) {
EXPECT_EQ(&n2, list.tail());
{
const int expected[] = {1, 2};
ExpectListContents(list, arraysize(expected), expected);
ExpectListContents(list, base::size(expected), expected);
}

n3.InsertBefore(&n2);
Expand All @@ -214,7 +214,7 @@ TEST(LinkedList, InsertBefore) {
EXPECT_EQ(&n2, list.tail());
{
const int expected[] = {1, 3, 2};
ExpectListContents(list, arraysize(expected), expected);
ExpectListContents(list, base::size(expected), expected);
}

n4.InsertBefore(&n1);
Expand All @@ -223,7 +223,7 @@ TEST(LinkedList, InsertBefore) {
EXPECT_EQ(&n2, list.tail());
{
const int expected[] = {4, 1, 3, 2};
ExpectListContents(list, arraysize(expected), expected);
ExpectListContents(list, base::size(expected), expected);
}
}

Expand All @@ -242,7 +242,7 @@ TEST(LinkedList, InsertAfter) {
EXPECT_EQ(&n2, list.tail());
{
const int expected[] = {1, 2};
ExpectListContents(list, arraysize(expected), expected);
ExpectListContents(list, base::size(expected), expected);
}

n3.InsertAfter(&n2);
Expand All @@ -251,7 +251,7 @@ TEST(LinkedList, InsertAfter) {
EXPECT_EQ(&n3, list.tail());
{
const int expected[] = {1, 2, 3};
ExpectListContents(list, arraysize(expected), expected);
ExpectListContents(list, base::size(expected), expected);
}

n4.InsertAfter(&n1);
Expand All @@ -260,7 +260,7 @@ TEST(LinkedList, InsertAfter) {
EXPECT_EQ(&n3, list.tail());
{
const int expected[] = {1, 4, 2, 3};
ExpectListContents(list, arraysize(expected), expected);
ExpectListContents(list, base::size(expected), expected);
}
}

Expand Down
6 changes: 3 additions & 3 deletions base/containers/span_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <vector>

#include "base/containers/checked_iterators.h"
#include "base/macros.h"
#include "base/stl_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

Expand Down Expand Up @@ -105,7 +105,7 @@ TEST(SpanTest, ConstructFromArray) {

span<const int> const_span(array);
EXPECT_EQ(array, const_span.data());
EXPECT_EQ(arraysize(array), const_span.size());
EXPECT_EQ(base::size(array), const_span.size());
for (size_t i = 0; i < const_span.size(); ++i)
EXPECT_EQ(array[i], const_span[i]);

Expand Down Expand Up @@ -1070,7 +1070,7 @@ TEST(SpanTest, EnsureConstexprGoodness) {

constexpr span<const int> lasts = constexpr_span.last(size);
for (size_t i = 0; i < lasts.size(); ++i) {
const size_t j = (arraysize(kArray) - size) + i;
const size_t j = (base::size(kArray) - size) + i;
EXPECT_EQ(kArray[j], lasts[i]);
}

Expand Down
6 changes: 3 additions & 3 deletions base/cpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <algorithm>
#include <utility>

#include "base/macros.h"
#include "base/stl_util.h"
#include "build/build_config.h"

#if defined(ARCH_CPU_ARM_FAMILY) && (defined(OS_ANDROID) || defined(OS_LINUX))
Expand Down Expand Up @@ -147,7 +147,7 @@ void CPU::Initialize() {
int num_ids = cpu_info[0];
std::swap(cpu_info[2], cpu_info[3]);
static constexpr size_t kVendorNameSize = 3 * sizeof(cpu_info[1]);
static_assert(kVendorNameSize < arraysize(cpu_string),
static_assert(kVendorNameSize < base::size(cpu_string),
"cpu_string too small");
memcpy(cpu_string, &cpu_info[1], kVendorNameSize);
cpu_string[kVendorNameSize] = '\0';
Expand Down Expand Up @@ -202,7 +202,7 @@ void CPU::Initialize() {
static constexpr int kParameterStart = 0x80000002;
static constexpr int kParameterEnd = 0x80000004;
static constexpr int kParameterSize = kParameterEnd - kParameterStart + 1;
static_assert(kParameterSize * sizeof(cpu_info) + 1 == arraysize(cpu_string),
static_assert(kParameterSize * sizeof(cpu_info) + 1 == base::size(cpu_string),
"cpu_string has wrong size");

if (max_parameter >= kParameterEnd) {
Expand Down
Loading

0 comments on commit e3b70bf

Please sign in to comment.