Commit e293d625 authored by Avi Drissman's avatar Avi Drissman Committed by Commit Bot

Use base::size rather than arraysize in tools/.

This is purely a mechanical change; there is no intended behavior change.

BUG=837308
TBR=thakis@chromium.org

Change-Id: I3d6c3cdc444b942e2f719075235d372d77891c44
Reviewed-on: https://chromium-review.googlesource.com/c/1390109Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#618835}
parent e49c86c9
......@@ -15,8 +15,8 @@
#include <unistd.h>
#include "base/logging.h"
#include "base/macros.h"
#include "base/posix/eintr_wrapper.h"
#include "base/stl_util.h"
#include "tools/android/common/net.h"
namespace tools {
......@@ -39,19 +39,19 @@ int ConnectAdbHostSocket(const char* forward_to) {
const size_t kLengthOfLength = 4;
const char kAddressPrefix[] = { 't', 'c', 'p', ':' };
size_t address_length = arraysize(kAddressPrefix) + strlen(forward_to);
size_t address_length = base::size(kAddressPrefix) + strlen(forward_to);
if (address_length > kBufferMaxLength - kLengthOfLength) {
LOG(ERROR) << "Forward to address is too long: " << forward_to;
return -1;
}
char request[kBufferMaxLength];
memcpy(request + kLengthOfLength, kAddressPrefix, arraysize(kAddressPrefix));
memcpy(request + kLengthOfLength + arraysize(kAddressPrefix),
forward_to, strlen(forward_to));
memcpy(request + kLengthOfLength, kAddressPrefix, base::size(kAddressPrefix));
memcpy(request + kLengthOfLength + base::size(kAddressPrefix), forward_to,
strlen(forward_to));
char length_buffer[kLengthOfLength + 1];
snprintf(length_buffer, arraysize(length_buffer), "%04X",
snprintf(length_buffer, base::size(length_buffer), "%04X",
static_cast<int>(address_length));
memcpy(request, length_buffer, kLengthOfLength);
......
......@@ -14,9 +14,9 @@
#include "base/callback_helpers.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/posix/eintr_wrapper.h"
#include "base/stl_util.h"
#include "tools/android/forwarder2/forwarder.h"
#include "tools/android/forwarder2/socket.h"
......@@ -81,7 +81,7 @@ void ForwardersManager::WaitForEventsOnInternalThread() {
deletion_notifier_.receiver_fd(),
};
for (size_t i = 0; i < arraysize(notifier_fds); ++i) {
for (size_t i = 0; i < base::size(notifier_fds); ++i) {
const int notifier_fd = notifier_fds[i];
DCHECK_GT(notifier_fd, -1);
FD_SET(notifier_fd, &read_fds);
......
......@@ -97,7 +97,7 @@ def _FormatSourceHeader(root, output_dir, include_gzipped):
#include <stddef.h>
#include "base/macros.h"
#include "base/stl_util.h"
#include "%(rc_header_file)s"
......@@ -114,7 +114,7 @@ def _FormatSourceFooter(root):
return '''\
};
const size_t %(map_name)sSize = arraysize(%(map_name)s);
const size_t %(map_name)sSize = base::size(%(map_name)s);
''' % { 'map_name': GetMapName(root) }
......
......@@ -64,7 +64,7 @@ extern const size_t kTheRcHeaderSize;''', output)
self.assertEqual('''\
#include "the_resource_map_header.h"
#include <stddef.h>
#include "base/macros.h"
#include "base/stl_util.h"
#include "the_rc_header.h"
const GritResourceMap kTheRcHeader[] = {
{"IDC_KLONKMENU", IDC_KLONKMENU},
......@@ -72,13 +72,13 @@ const GritResourceMap kTheRcHeader[] = {
{"IDS_LANGUAGESPECIFIC", IDS_LANGUAGESPECIFIC},
{"IDS_THIRDPRESENT", IDS_THIRDPRESENT},
};
const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output)
const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output)
output = util.StripBlankLinesAndComments(''.join(
resource_map.GetFormatter('resource_file_map_source')(grd, 'en', '.')))
self.assertEqual('''\
#include "the_resource_map_header.h"
#include <stddef.h>
#include "base/macros.h"
#include "base/stl_util.h"
#include "the_rc_header.h"
const GritResourceMap kTheRcHeader[] = {
{"grit/testdata/klonk.rc", IDC_KLONKMENU},
......@@ -86,7 +86,7 @@ const GritResourceMap kTheRcHeader[] = {
{"ghi", IDS_LANGUAGESPECIFIC},
{"mno", IDS_THIRDPRESENT},
};
const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output)
const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output)
def testGzippedMapHeaderAndFileSource(self):
grd = util.ParseGrdForUnittest('''\
......@@ -128,13 +128,13 @@ extern const size_t kTheRcHeaderSize;''', output)
self.assertEqual('''\
#include "gzipped_resource_map_header.h"
#include <stddef.h>
#include "base/macros.h"
#include "base/stl_util.h"
#include "the_rc_header.h"
const GzippedGritResourceMap kTheRcHeader[] = {
{"grit/testdata/klonk.rc", IDC_KLONKMENU, true},
{"abc", IDS_FIRSTPRESENT, false},
};
const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output)
const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output)
def testFormatResourceMapWithOutputAllEqualsFalseForStructures(self):
grd = util.ParseGrdForUnittest('''
......@@ -195,7 +195,7 @@ extern const size_t kTheRcHeaderSize;''', output)
self.assertEqual('''\
#include "the_resource_map_header.h"
#include <stddef.h>
#include "base/macros.h"
#include "base/stl_util.h"
#include "the_rc_header.h"
const GritResourceMap kTheRcHeader[] = {
{"IDR_KLONKMENU", IDR_KLONKMENU},
......@@ -203,13 +203,13 @@ const GritResourceMap kTheRcHeader[] = {
{"IDR_METEOR", IDR_METEOR},
{"IDR_LAST", IDR_LAST},
};
const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output)
const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output)
output = util.StripBlankLinesAndComments(''.join(
resource_map.GetFormatter('resource_map_source')(grd, 'en', '.')))
self.assertEqual('''\
#include "the_resource_map_header.h"
#include <stddef.h>
#include "base/macros.h"
#include "base/stl_util.h"
#include "the_rc_header.h"
const GritResourceMap kTheRcHeader[] = {
{"IDR_KLONKMENU", IDR_KLONKMENU},
......@@ -217,7 +217,7 @@ const GritResourceMap kTheRcHeader[] = {
{"IDR_METEOR", IDR_METEOR},
{"IDR_LAST", IDR_LAST},
};
const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output)
const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output)
def testFormatResourceMapWithOutputAllEqualsFalseForIncludes(self):
grd = util.ParseGrdForUnittest('''
......@@ -274,7 +274,7 @@ extern const size_t kTheRcHeaderSize;''', output)
self.assertEqual('''\
#include "the_resource_map_header.h"
#include <stddef.h>
#include "base/macros.h"
#include "base/stl_util.h"
#include "the_rc_header.h"
const GritResourceMap kTheRcHeader[] = {
{"IDC_KLONKMENU", IDC_KLONKMENU},
......@@ -284,13 +284,13 @@ const GritResourceMap kTheRcHeader[] = {
{"IDS_METEOR", IDS_METEOR},
{"IDS_LAST", IDS_LAST},
};
const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output)
const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output)
output = util.StripBlankLinesAndComments(''.join(
resource_map.GetFormatter('resource_file_map_source')(grd, 'en', '.')))
self.assertEqual('''\
#include "the_resource_map_header.h"
#include <stddef.h>
#include "base/macros.h"
#include "base/stl_util.h"
#include "the_rc_header.h"
const GritResourceMap kTheRcHeader[] = {
{"grit/testdata/klonk.rc", IDC_KLONKMENU},
......@@ -300,7 +300,7 @@ const GritResourceMap kTheRcHeader[] = {
{"meteor", IDS_METEOR},
{"xyz", IDS_LAST},
};
const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output)
const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output)
def testFormatStringResourceMap(self):
grd = util.ParseGrdForUnittest('''
......@@ -347,13 +347,13 @@ extern const size_t kTheRcHeaderSize;''', output)
self.assertEqual('''\
#include "the_rc_map_header.h"
#include <stddef.h>
#include "base/macros.h"
#include "base/stl_util.h"
#include "the_rc_header.h"
const GritResourceMap kTheRcHeader[] = {
{"IDS_PRODUCT_NAME", IDS_PRODUCT_NAME},
{"IDS_DEFAULT_TAB_TITLE_TITLE_CASE", IDS_DEFAULT_TAB_TITLE_TITLE_CASE},
};
const size_t kTheRcHeaderSize = arraysize(kTheRcHeader);''', output)
const size_t kTheRcHeaderSize = base::size(kTheRcHeader);''', output)
if __name__ == '__main__':
......
......@@ -10,9 +10,9 @@
#include <vector>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/memory/shared_memory_handle.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/unguessable_token.h"
#include "base/values.h"
......@@ -907,10 +907,10 @@ template <>
struct FuzzTraits<gfx::Transform> {
static bool Fuzz(gfx::Transform* p, Fuzzer* fuzzer) {
SkMScalar matrix[16];
for (size_t i = 0; i < arraysize(matrix); i++) {
for (size_t i = 0; i < base::size(matrix); i++) {
matrix[i] = p->matrix().get(i / 4, i % 4);
}
if (!FuzzParamArray(&matrix[0], arraysize(matrix), fuzzer))
if (!FuzzParamArray(&matrix[0], base::size(matrix), fuzzer))
return false;
*p = gfx::Transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4],
matrix[5], matrix[6], matrix[7], matrix[8], matrix[9],
......
......@@ -9,7 +9,7 @@
#include <memory>
#include <utility>
#include "base/macros.h"
#include "base/stl_util.h"
#include "base/values.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "tools/json_schema_compiler/test/enums.h"
......@@ -77,7 +77,7 @@ TEST(JsonSchemaCompilerArrayTest, EnumArrayReference) {
Enumeration expected_types[] = {ENUMERATION_ONE, ENUMERATION_TWO,
ENUMERATION_THREE};
EXPECT_EQ(std::vector<Enumeration>(
expected_types, expected_types + arraysize(expected_types)),
expected_types, expected_types + base::size(expected_types)),
enum_array_reference.types);
// Test ToValue.
......@@ -110,7 +110,7 @@ TEST(JsonSchemaCompilerArrayTest, EnumArrayMixed) {
ENUMERATION_THREE};
EXPECT_EQ(std::vector<Enumeration>(
expected_infile_types,
expected_infile_types + arraysize(expected_infile_types)),
expected_infile_types + base::size(expected_infile_types)),
enum_array_mixed.infile_enums);
test::api::enums::Enumeration expected_external_types[] = {
......@@ -118,7 +118,7 @@ TEST(JsonSchemaCompilerArrayTest, EnumArrayMixed) {
test::api::enums::ENUMERATION_THREE};
EXPECT_EQ(std::vector<test::api::enums::Enumeration>(
expected_external_types,
expected_external_types + arraysize(expected_external_types)),
expected_external_types + base::size(expected_external_types)),
enum_array_mixed.external_enums);
// Test ToValue.
......
......@@ -201,7 +201,7 @@ TEST_F(TrafficAnnotationAuditorTest, GetFilesFromGit) {
const std::vector<std::string> git_files = filter.git_files();
EXPECT_EQ(git_files.size(), arraysize(kRelevantFiles));
EXPECT_EQ(git_files.size(), base::size(kRelevantFiles));
for (const char* filepath : kRelevantFiles) {
EXPECT_TRUE(base::ContainsValue(git_files, filepath));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment