Skip to content

Commit

Permalink
Use base::size rather than arraysize in device/.
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
TBR=rockot@google.com

Change-Id: If4b83253ade42613e9683b69e187b79a2a940b98
Reviewed-on: https://chromium-review.googlesource.com/c/1390730
Reviewed-by: Avi Drissman <avi@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#618878}
  • Loading branch information
Avi Drissman authored and Commit Bot committed Dec 25, 2018
1 parent 197295a commit 141d025
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 44 deletions.
5 changes: 2 additions & 3 deletions device/bluetooth/bluetooth_device_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <stddef.h>

#include "base/macros.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
Expand Down Expand Up @@ -65,7 +64,7 @@ TEST(BluetoothDeviceTest, CanonicalizeAddressFormat_AcceptsAllValidFormats) {
"1a2b3c4d5e6f",
};

for (size_t i = 0; i < arraysize(kValidFormats); ++i) {
for (size_t i = 0; i < base::size(kValidFormats); ++i) {
SCOPED_TRACE(std::string("Input format: '") + kValidFormats[i] + "'");
EXPECT_EQ("1A:2B:3C:4D:5E:6F",
BluetoothDevice::CanonicalizeAddress(kValidFormats[i]));
Expand All @@ -90,7 +89,7 @@ TEST(BluetoothDeviceTest, CanonicalizeAddressFormat_RejectsInvalidFormats) {
"1:A2:B3:C4:D5:E6F",
};

for (size_t i = 0; i < arraysize(kValidFormats); ++i) {
for (size_t i = 0; i < base::size(kValidFormats); ++i) {
SCOPED_TRACE(std::string("Input format: '") + kValidFormats[i] + "'");
EXPECT_EQ(std::string(),
BluetoothDevice::CanonicalizeAddress(kValidFormats[i]));
Expand Down
3 changes: 2 additions & 1 deletion device/bluetooth/bluetooth_gatt_descriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vector>

#include "base/lazy_instance.h"
#include "base/stl_util.h"

namespace device {
namespace {
Expand All @@ -24,7 +25,7 @@ struct UUIDs {
"0x2900", "0x2901", "0x2902", "0x2903", "0x2904", "0x2905"
};

for (size_t i = 0; i < arraysize(strings); ++i)
for (size_t i = 0; i < base::size(strings); ++i)
uuids.push_back(BluetoothUUID(strings[i]));

return uuids;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <utility>

#include "base/bind.h"
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/test/bind_test_util.h"
#include "build/build_config.h"
#include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
Expand Down Expand Up @@ -807,7 +807,7 @@ TEST_F(BluetoothRemoteGattCharacteristicTest, MAYBE_WriteRemoteCharacteristic) {
TestBluetoothAdapterObserver observer(adapter_);

uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
std::vector<uint8_t> test_vector(values, values + arraysize(values));
std::vector<uint8_t> test_vector(values, values + base::size(values));
characteristic1_->WriteRemoteCharacteristic(
test_vector, GetCallback(Call::EXPECTED),
GetGattErrorCallback(Call::NOT_EXPECTED));
Expand Down Expand Up @@ -848,7 +848,7 @@ TEST_F(BluetoothRemoteGattCharacteristicTest,
GetGattErrorCallback(Call::NOT_EXPECTED));

uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
std::vector<uint8_t> test_vector(values, values + arraysize(values));
std::vector<uint8_t> test_vector(values, values + base::size(values));
SimulateGattCharacteristicRead(characteristic1_, test_vector);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, gatt_read_characteristic_attempts_);
Expand Down Expand Up @@ -894,7 +894,7 @@ TEST_F(BluetoothRemoteGattCharacteristicTest,
BluetoothRemoteGattCharacteristic::PROPERTY_WRITE));

uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
std::vector<uint8_t> test_vector(values, values + arraysize(values));
std::vector<uint8_t> test_vector(values, values + base::size(values));
characteristic1_->WriteRemoteCharacteristic(
test_vector, GetCallback(Call::EXPECTED),
GetGattErrorCallback(Call::NOT_EXPECTED));
Expand Down
11 changes: 6 additions & 5 deletions device/bluetooth/bluetooth_remote_gatt_descriptor_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

#include "base/run_loop.h"
#include "base/stl_util.h"
#include "build/build_config.h"
#include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
#include "device/bluetooth/bluetooth_remote_gatt_service.h"
Expand Down Expand Up @@ -369,7 +370,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_ReadRemoteDescriptor) {
EXPECT_EQ(1, gatt_read_descriptor_attempts_);

uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
std::vector<uint8_t> test_vector(values, values + arraysize(values));
std::vector<uint8_t> test_vector(values, values + base::size(values));
SimulateGattDescriptorRead(descriptor1_, test_vector);
base::RunLoop().RunUntilIdle();

Expand Down Expand Up @@ -400,7 +401,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_WriteRemoteDescriptor) {
ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate());

uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
std::vector<uint8_t> test_vector(values, values + arraysize(values));
std::vector<uint8_t> test_vector(values, values + base::size(values));
descriptor1_->WriteRemoteDescriptor(test_vector, GetCallback(Call::EXPECTED),
GetGattErrorCallback(Call::NOT_EXPECTED));
EXPECT_EQ(1, gatt_write_descriptor_attempts_);
Expand Down Expand Up @@ -433,7 +434,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_ReadRemoteDescriptor_Twice) {
EXPECT_EQ(1, gatt_read_descriptor_attempts_);

uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
std::vector<uint8_t> test_vector(values, values + arraysize(values));
std::vector<uint8_t> test_vector(values, values + base::size(values));
SimulateGattDescriptorRead(descriptor1_, test_vector);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, callback_count_);
Expand Down Expand Up @@ -474,7 +475,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, MAYBE_WriteRemoteDescriptor_Twice) {
ASSERT_NO_FATAL_FAILURE(FakeDescriptorBoilerplate());

uint8_t values[] = {0, 1, 2, 3, 4, 0xf, 0xf0, 0xff};
std::vector<uint8_t> test_vector(values, values + arraysize(values));
std::vector<uint8_t> test_vector(values, values + base::size(values));
descriptor1_->WriteRemoteDescriptor(test_vector, GetCallback(Call::EXPECTED),
GetGattErrorCallback(Call::NOT_EXPECTED));
EXPECT_EQ(1, gatt_write_descriptor_attempts_);
Expand Down Expand Up @@ -988,7 +989,7 @@ TEST_F(BluetoothRemoteGattDescriptorTest, ReadRemoteDescriptor_NSNumber) {
base::RunLoop().RunUntilIdle();

uint8_t values[] = {0x34, 0x12};
std::vector<uint8_t> test_vector(values, values + arraysize(values));
std::vector<uint8_t> test_vector(values, values + base::size(values));
EXPECT_EQ(test_vector, last_read_value_);
EXPECT_EQ(test_vector, descriptor1_->GetValue());
}
Expand Down
4 changes: 2 additions & 2 deletions device/bluetooth/bluetooth_uuid_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <stddef.h>

#include "base/macros.h"
#include "base/stl_util.h"
#include "base/strings/string_piece.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand Down Expand Up @@ -141,7 +141,7 @@ TEST(BluetoothUUIDTest, BluetoothUUID_CaseInsensitive) {
{ "00001aBc-0000-1000-8000-00805F9b34fB", k128Bit },
};

for (size_t i = 0; i < arraysize(test_cases); ++i) {
for (size_t i = 0; i < base::size(test_cases); ++i) {
SCOPED_TRACE("Input UUID: " + test_cases[i].input_uuid);
BluetoothUUID uuid(test_cases[i].input_uuid);
EXPECT_TRUE(uuid.IsValid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <sstream>

#include "base/bind.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/stl_util.h"
#include "device/bluetooth/dbus/bluetooth_media_client.h"
#include "device/bluetooth/dbus/bluez_dbus_manager.h"
#include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h"
Expand Down Expand Up @@ -44,7 +44,7 @@ ObjectPath GenerateTransportPath() {
}

#define UINT8_VECTOR_FROM_ARRAY(array) \
std::vector<uint8_t>(array, array + arraysize(array))
std::vector<uint8_t>(array, array + base::size(array))

} // namespace

Expand All @@ -57,7 +57,7 @@ const uint8_t FakeBluetoothMediaTransportClient::kTransportCodec = 0x00;
const uint8_t FakeBluetoothMediaTransportClient::kTransportConfiguration[] = {
0x21, 0x15, 0x33, 0x2C};
const uint8_t FakeBluetoothMediaTransportClient::kTransportConfigurationLength =
arraysize(FakeBluetoothMediaTransportClient::kTransportConfiguration);
base::size(FakeBluetoothMediaTransportClient::kTransportConfiguration);
const uint16_t FakeBluetoothMediaTransportClient::kTransportDelay = 5;
const uint16_t FakeBluetoothMediaTransportClient::kTransportVolume = 50;
const uint16_t FakeBluetoothMediaTransportClient::kDefaultReadMtu = 20;
Expand Down
10 changes: 5 additions & 5 deletions device/bluetooth/uribeacon/uri_encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/macros.h"
#include "uri_encoder.h"
#include "base/stl_util.h"

using base::StringPiece;

Expand Down Expand Up @@ -70,26 +70,26 @@ struct expansion* CommonLookupExpansionByValue(struct expansion* table,
struct expansion* LookupExpansionByValue(const std::string& input,
int input_index) {
return CommonLookupExpansionByValue(
expansions_list, arraysize(expansions_list), input, input_index);
expansions_list, base::size(expansions_list), input, input_index);
}

struct expansion* LookupPrefixExpansionByValue(const std::string& input,
int input_index) {
return CommonLookupExpansionByValue(prefix_expansions_list,
arraysize(prefix_expansions_list), input,
base::size(prefix_expansions_list), input,
input_index);
}

struct expansion* LookupExpansionByCode(const std::vector<uint8_t>& input,
int input_index) {
if (input[input_index] >= arraysize(expansions_list))
if (input[input_index] >= base::size(expansions_list))
return NULL;
return &expansions_list[input[input_index]];
}

struct expansion* LookupPrefixExpansionByCode(const std::vector<uint8_t>& input,
int input_index) {
if (input[input_index] >= arraysize(prefix_expansions_list))
if (input[input_index] >= base::size(prefix_expansions_list))
return NULL;
return &prefix_expansions_list[input[input_index]];
}
Expand Down
3 changes: 2 additions & 1 deletion device/fido/ctap_response_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/stl_util.h"
#include "components/cbor/reader.h"
#include "components/cbor/values.h"
#include "components/cbor/writer.h"
Expand Down Expand Up @@ -298,7 +299,7 @@ std::vector<uint8_t> GetTestSignResponse() {

// Get a subset of the response for testing error handling.
std::vector<uint8_t> GetTestCorruptedSignResponse(size_t length) {
DCHECK_LE(length, arraysize(test_data::kTestU2fSignResponse));
DCHECK_LE(length, base::size(test_data::kTestU2fSignResponse));
return fido_parsing_utils::Materialize(fido_parsing_utils::ExtractSpan(
test_data::kTestU2fSignResponse, 0, length));
}
Expand Down
5 changes: 3 additions & 2 deletions device/gamepad/gamepad_platform_data_fetcher_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
Expand Down Expand Up @@ -77,7 +78,7 @@ void GamepadPlatformDataFetcherLinux::UpdateGamepadStrings(
base::TruncateUTF8ToByteSize(id, Gamepad::kIdLengthCap - 1, &id);
base::string16 tmp16 = base::UTF8ToUTF16(id);
memset(pad->id, 0, sizeof(pad->id));
tmp16.copy(pad->id, arraysize(pad->id) - 1);
tmp16.copy(pad->id, base::size(pad->id) - 1);

// Set the mapper string to "standard" if the gamepad has a standard mapping,
// or the empty string otherwise.
Expand All @@ -87,7 +88,7 @@ void GamepadPlatformDataFetcherLinux::UpdateGamepadStrings(
&mapping);
tmp16 = base::UTF8ToUTF16(mapping);
memset(pad->mapping, 0, sizeof(pad->mapping));
tmp16.copy(pad->mapping, arraysize(pad->mapping) - 1);
tmp16.copy(pad->mapping, base::size(pad->mapping) - 1);
} else {
pad->mapping[0] = 0;
}
Expand Down
8 changes: 4 additions & 4 deletions device/gamepad/raw_input_data_fetcher_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <stddef.h>

#include "base/macros.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/trace_event/trace_event.h"
#include "device/gamepad/gamepad_standard_mappings.h"
Expand Down Expand Up @@ -43,7 +43,7 @@ void RawInputDataFetcher::OnAddedToProvider() {
}

RAWINPUTDEVICE* RawInputDataFetcher::GetRawInputDevices(DWORD flags) {
size_t usage_count = arraysize(DeviceUsages);
size_t usage_count = base::size(DeviceUsages);
std::unique_ptr<RAWINPUTDEVICE[]> devices(new RAWINPUTDEVICE[usage_count]);
for (size_t i = 0; i < usage_count; ++i) {
devices[i].dwFlags = flags;
Expand Down Expand Up @@ -78,7 +78,7 @@ void RawInputDataFetcher::StartMonitor() {
// Register to receive raw HID input.
std::unique_ptr<RAWINPUTDEVICE[]> devices(
GetRawInputDevices(RIDEV_INPUTSINK));
if (!::RegisterRawInputDevices(devices.get(), arraysize(DeviceUsages),
if (!::RegisterRawInputDevices(devices.get(), base::size(DeviceUsages),
sizeof(RAWINPUTDEVICE))) {
PLOG(ERROR) << "RegisterRawInputDevices() failed for RIDEV_INPUTSINK";
window_.reset();
Expand All @@ -96,7 +96,7 @@ void RawInputDataFetcher::StopMonitor() {
DCHECK(window_);
std::unique_ptr<RAWINPUTDEVICE[]> devices(GetRawInputDevices(RIDEV_REMOVE));

if (!::RegisterRawInputDevices(devices.get(), arraysize(DeviceUsages),
if (!::RegisterRawInputDevices(devices.get(), base::size(DeviceUsages),
sizeof(RAWINPUTDEVICE))) {
PLOG(INFO) << "RegisterRawInputDevices() failed for RIDEV_REMOVE";
}
Expand Down
7 changes: 4 additions & 3 deletions device/gamepad/xbox_data_fetcher_mac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "base/logging.h"
#include "base/mac/foundation_util.h"
#include "base/stl_util.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"

Expand Down Expand Up @@ -314,9 +315,9 @@ void XboxDataFetcher::AddController(XboxControllerMac* controller) {
controller->SetLEDPattern((XboxControllerMac::LEDPattern)(
XboxControllerMac::LED_FLASH_TOP_LEFT + controller->location_id()));

CopyToUString(state->data.id, arraysize(state->data.id),
CopyToUString(state->data.id, base::size(state->data.id),
base::UTF8ToUTF16(controller->GetIdString()));
CopyToUString(state->data.mapping, arraysize(state->data.mapping),
CopyToUString(state->data.mapping, base::size(state->data.mapping),
base::UTF8ToUTF16("standard"));

state->data.connected = true;
Expand Down Expand Up @@ -376,7 +377,7 @@ void XboxDataFetcher::XboxControllerGotData(
pad.buttons[16].pressed = data.buttons[14];
pad.buttons[16].value = data.buttons[14] ? 1.0f : 0.0f;
}
for (size_t i = 0; i < arraysize(data.axes); i++) {
for (size_t i = 0; i < base::size(data.axes); i++) {
pad.axes[i] = data.axes[i];
}

Expand Down
6 changes: 3 additions & 3 deletions device/test/usb_test_gadget_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
#include "base/files/file_path.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
#include "base/path_service.h"
#include "base/process/process_handle.h"
#include "base/run_loop.h"
#include "base/scoped_observer.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
Expand Down Expand Up @@ -437,7 +437,7 @@ class DeviceAddListener : public UsbService::Observer {
const uint16_t product_id = device->product_id();
if (product_id_ == -1) {
bool found = false;
for (size_t i = 0; i < arraysize(kConfigurations); ++i) {
for (size_t i = 0; i < base::size(kConfigurations); ++i) {
if (product_id == kConfigurations[i].product_id) {
found = true;
break;
Expand Down Expand Up @@ -569,7 +569,7 @@ bool UsbTestGadgetImpl::Unclaim() {

bool UsbTestGadgetImpl::SetType(Type type) {
const struct UsbTestGadgetConfiguration* config = NULL;
for (size_t i = 0; i < arraysize(kConfigurations); ++i) {
for (size_t i = 0; i < base::size(kConfigurations); ++i) {
if (kConfigurations[i].type == type) {
config = &kConfigurations[i];
}
Expand Down
13 changes: 7 additions & 6 deletions device/vr/openvr/test/fake_openvr_impl_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <D3D11_1.h>
#include <DXGI1_4.h>
#include <wrl.h>
#include <memory>

#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "device/vr/openvr/test/test_helper.h"
#include "device/vr/openvr/test/test_hook.h"
#include "third_party/openvr/src/headers/openvr.h"
#include "third_party/openvr/src/src/ivrclientcore.h"

#include <D3D11_1.h>
#include <DXGI1_4.h>
#include <wrl.h>
#include <memory>

// TODO(https://crbug.com/892717): Update argument names to be consistent with
// Chromium style guidelines.
namespace vr {
Expand Down Expand Up @@ -440,7 +441,7 @@ void TestVRSystem::GetDXGIOutputInfo(int32_t* adapter_index) {
Microsoft::WRL::ComPtr<ID3D11DeviceContext> d3d11_device_context;
if (SUCCEEDED(D3D11CreateDevice(
adapter.Get(), D3D_DRIVER_TYPE_UNKNOWN, NULL, flags, feature_levels,
arraysize(feature_levels), D3D11_SDK_VERSION,
base::size(feature_levels), D3D11_SDK_VERSION,
d3d11_device.GetAddressOf(), &feature_level_out,
d3d11_device_context.GetAddressOf()))) {
*adapter_index = i;
Expand Down
Loading

0 comments on commit 141d025

Please sign in to comment.