0

spanify: Renewed arrayification (X/43)

This CL is part of the wider spanification / arrayification effort [1]
and does not (intentionally) introduce behavioral change. It applies the
`std::array` rewrite to

services

as close as possible to the output directly written by `spanify`, with
no hand-rolled fixes (except where rebasing would require).

This change (and its siblings taken together) is thought not to cause
any measurable perf regressions [2].

[1] https://issues.chromium.org/356643982
[2] https://docs.google.com/document/d/1jughaR6JKn7T-dDjMou10awyNkhE5T-vLY_K2YMqHE4/edit?tab=t.0#heading=h.r2eguxl5lhu7

This CL was uploaded by an experimental version of git cl split
(https://crbug.com/389069356).

Bug: 406029216
AX-Relnotes: n/a.
Change-Id: I0eff45c17c22f47db9e58bd38aa03695768ed6f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6433381
Auto-Submit: Kalvin Lee <kdlee@chromium.org>
Commit-Queue: Alex Gough <ajgo@chromium.org>
Reviewed-by: Alex Gough <ajgo@chromium.org>
Reviewed-by: Stephen Nusko <nuskos@chromium.org>
Owners-Override: Alex Gough <ajgo@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1448507}
This commit is contained in:
Kalvin Lee
2025-04-17 12:31:15 -07:00
committed by Chromium LUCI CQ
parent 6a0a7ead8d
commit 2526d544f9
7 changed files with 23 additions and 14 deletions

@@ -649,7 +649,7 @@ size_t SerialIoHandlerPosix::CheckReceiveError(base::span<uint8_t> buffer,
new_bytes_read - buffer.size() == 2) { new_bytes_read - buffer.size() == 2) {
// need to stash the last two characters // need to stash the last two characters
if (new_bytes_read == 2) { if (new_bytes_read == 2) {
memcpy(tmp, chars_stashed_, new_bytes_read); memcpy(tmp, chars_stashed_.data(), new_bytes_read);
} else { } else {
if (new_bytes_read == 3) { if (new_bytes_read == 3) {
tmp[0] = chars_stashed_[1]; tmp[0] = chars_stashed_[1];
@@ -675,8 +675,9 @@ size_t SerialIoHandlerPosix::CheckReceiveError(base::span<uint8_t> buffer,
// right shift two bytes to store bytes from chars_stashed_[] // right shift two bytes to store bytes from chars_stashed_[]
memmove(&buffer[2], &buffer[0], new_bytes_read - 2); memmove(&buffer[2], &buffer[0], new_bytes_read - 2);
} }
memcpy(&buffer[0], chars_stashed_, std::min<size_t>(new_bytes_read, 2)); memcpy(&buffer[0], chars_stashed_.data(),
memcpy(chars_stashed_, tmp, num_chars_stashed_); std::min<size_t>(new_bytes_read, 2));
memcpy(chars_stashed_.data(), tmp, num_chars_stashed_);
return new_bytes_read; return new_bytes_read;
} }

@@ -5,6 +5,7 @@
#ifndef SERVICES_DEVICE_SERIAL_SERIAL_IO_HANDLER_POSIX_H_ #ifndef SERVICES_DEVICE_SERIAL_SERIAL_IO_HANDLER_POSIX_H_
#define SERVICES_DEVICE_SERIAL_SERIAL_IO_HANDLER_POSIX_H_ #define SERVICES_DEVICE_SERIAL_SERIAL_IO_HANDLER_POSIX_H_
#include <array>
#include <memory> #include <memory>
#include "base/files/file_descriptor_watcher_posix.h" #include "base/files/file_descriptor_watcher_posix.h"
@@ -68,7 +69,7 @@ class SerialIoHandlerPosix : public SerialIoHandler {
ErrorDetectState error_detect_state_; ErrorDetectState error_detect_state_;
bool parity_check_enabled_; bool parity_check_enabled_;
uint8_t chars_stashed_[2]; std::array<uint8_t, 2> chars_stashed_;
size_t num_chars_stashed_; size_t num_chars_stashed_;
}; };

@@ -10,6 +10,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <array>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
@@ -83,13 +84,13 @@ struct UsbTestGadgetConfiguration {
uint16_t product_id; uint16_t product_id;
}; };
static const struct UsbTestGadgetConfiguration kConfigurations[] = { static const auto kConfigurations = std::to_array<UsbTestGadgetConfiguration>({
{UsbTestGadget::DEFAULT, "/unconfigure", 0x58F0}, {UsbTestGadget::DEFAULT, "/unconfigure", 0x58F0},
{UsbTestGadget::KEYBOARD, "/keyboard/configure", 0x58F1}, {UsbTestGadget::KEYBOARD, "/keyboard/configure", 0x58F1},
{UsbTestGadget::MOUSE, "/mouse/configure", 0x58F2}, {UsbTestGadget::MOUSE, "/mouse/configure", 0x58F2},
{UsbTestGadget::HID_ECHO, "/hid_echo/configure", 0x58F3}, {UsbTestGadget::HID_ECHO, "/hid_echo/configure", 0x58F3},
{UsbTestGadget::ECHO, "/echo/configure", 0x58F4}, {UsbTestGadget::ECHO, "/echo/configure", 0x58F4},
}; });
bool ReadFile(const base::FilePath& file_path, std::string* content) { bool ReadFile(const base::FilePath& file_path, std::string* content) {
base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ); base::File file(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ);

@@ -9,6 +9,7 @@
#include "services/network/mdns_responder.h" #include "services/network/mdns_responder.h"
#include <array>
#include <cstdint> #include <cstdint>
#include <map> #include <map>
#include <memory> #include <memory>
@@ -495,7 +496,7 @@ class MdnsResponderTest : public testing::Test {
// of time and avoid any actual sleeps. // of time and avoid any actual sleeps.
NiceMock<net::MockMDnsSocketFactory> socket_factory_; NiceMock<net::MockMDnsSocketFactory> socket_factory_;
NiceMock<MockFailingMdnsSocketFactory> failing_socket_factory_; NiceMock<MockFailingMdnsSocketFactory> failing_socket_factory_;
mojo::Remote<mojom::MdnsResponder> client_[2]; std::array<mojo::Remote<mojom::MdnsResponder>, 2> client_;
std::unique_ptr<MdnsResponderManager> host_manager_; std::unique_ptr<MdnsResponderManager> host_manager_;
std::string last_name_created_; std::string last_name_created_;
}; };

@@ -5,6 +5,7 @@
#ifndef SERVICES_NETWORK_WEBSOCKET_INTERCEPTOR_H_ #ifndef SERVICES_NETWORK_WEBSOCKET_INTERCEPTOR_H_
#define SERVICES_NETWORK_WEBSOCKET_INTERCEPTOR_H_ #define SERVICES_NETWORK_WEBSOCKET_INTERCEPTOR_H_
#include <array>
#include <optional> #include <optional>
#include "base/component_export.h" #include "base/component_export.h"
@@ -53,11 +54,12 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) WebSocketInterceptor {
private: private:
void ThrottleCallback(FrameDirection direction, int result, int64_t bytes); void ThrottleCallback(FrameDirection direction, int result, int64_t bytes);
ThrottlingNetworkInterceptor::ThrottleCallback throttle_callbacks_[2]; std::array<ThrottlingNetworkInterceptor::ThrottleCallback, 2>
throttle_callbacks_;
const uint32_t net_log_source_id_; const uint32_t net_log_source_id_;
const std::unique_ptr<ScopedThrottlingToken> throttling_token_; const std::unique_ptr<ScopedThrottlingToken> throttling_token_;
base::OnceClosure pending_callbacks_[2]; std::array<base::OnceClosure, 2> pending_callbacks_;
}; };
} // namespace network } // namespace network

@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ui/gfx/geometry/rect.h"
#ifdef UNSAFE_BUFFERS_BUILD #ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs. // TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers #pragma allow_unsafe_buffers
@@ -10,6 +9,7 @@
#include "services/screen_ai/proto/main_content_extractor_proto_convertor.h" #include "services/screen_ai/proto/main_content_extractor_proto_convertor.h"
#include <array>
#include <string_view> #include <string_view>
#include "base/files/file_path.h" #include "base/files/file_path.h"
@@ -24,6 +24,7 @@
#include "ui/accessibility/ax_node_data.h" #include "ui/accessibility/ax_node_data.h"
#include "ui/accessibility/ax_tree.h" #include "ui/accessibility/ax_tree.h"
#include "ui/accessibility/ax_tree_update.h" #include "ui/accessibility/ax_tree_update.h"
#include "ui/gfx/geometry/rect.h"
namespace { namespace {
@@ -37,7 +38,7 @@ constexpr int kMaxChildInTemplate = 3;
struct NodeTemplate { struct NodeTemplate {
ui::AXNodeID node_id; ui::AXNodeID node_id;
int child_count; int child_count;
ui::AXNodeID child_ids[kMaxChildInTemplate]; std::array<ui::AXNodeID, kMaxChildInTemplate> child_ids;
}; };
ui::AXTreeUpdate CreateAXTreeUpdateFromTemplate(int root_id, ui::AXTreeUpdate CreateAXTreeUpdateFromTemplate(int root_id,
@@ -340,7 +341,7 @@ TEST_F(MainContentExtractorProtoConvertorTest, PreOrderTreeGeneration) {
const int nodes_count = sizeof(input_tree) / sizeof(NodeTemplate); const int nodes_count = sizeof(input_tree) / sizeof(NodeTemplate);
// Expected order of nodes in the output. // Expected order of nodes in the output.
int expected_order[] = {1, 2, 7, 8, 3, 4, 5, 6, 9, -20}; auto expected_order = std::to_array<int>({1, 2, 7, 8, 3, 4, 5, 6, 9, -20});
// Create the tree, convert it, and decode from proto. // Create the tree, convert it, and decode from proto.
ui::AXTreeUpdate tree_update = ui::AXTreeUpdate tree_update =

@@ -9,6 +9,8 @@
#include "services/tracing/public/cpp/perfetto/trace_string_lookup.h" #include "services/tracing/public/cpp/perfetto/trace_string_lookup.h"
#include <array>
#include "base/strings/pattern.h" #include "base/strings/pattern.h"
using ::perfetto::protos::pbzero::ChromeThreadDescriptor; using ::perfetto::protos::pbzero::ChromeThreadDescriptor;
@@ -20,7 +22,7 @@ struct ThreadType {
ChromeThreadDescriptor::ThreadType type; ChromeThreadDescriptor::ThreadType type;
}; };
constexpr ThreadType kThreadTypes[] = { constexpr auto kThreadTypes = std::to_array<ThreadType>({
{"CrBrowserMain", ChromeThreadDescriptor::THREAD_BROWSER_MAIN}, {"CrBrowserMain", ChromeThreadDescriptor::THREAD_BROWSER_MAIN},
{"CrRendererMain", ChromeThreadDescriptor::THREAD_RENDERER_MAIN}, {"CrRendererMain", ChromeThreadDescriptor::THREAD_RENDERER_MAIN},
{"CrGpuMain", ChromeThreadDescriptor::THREAD_GPU_MAIN}, {"CrGpuMain", ChromeThreadDescriptor::THREAD_GPU_MAIN},
@@ -74,7 +76,7 @@ constexpr ThreadType kThreadTypes[] = {
{"wasapi_render_thread", ChromeThreadDescriptor::THREAD_WASAPI_RENDER}, {"wasapi_render_thread", ChromeThreadDescriptor::THREAD_WASAPI_RENDER},
{"LoaderLockSampler", ChromeThreadDescriptor::THREAD_LOADER_LOCK_SAMPLER}, {"LoaderLockSampler", ChromeThreadDescriptor::THREAD_LOADER_LOCK_SAMPLER},
{"CompositorGpuThread", ChromeThreadDescriptor::THREAD_COMPOSITOR_GPU}, {"CompositorGpuThread", ChromeThreadDescriptor::THREAD_COMPOSITOR_GPU},
}; });
ChromeThreadDescriptor::ThreadType GetThreadType( ChromeThreadDescriptor::ThreadType GetThreadType(
const char* const thread_name) { const char* const thread_name) {