General: Remove usages of ARRAY_SIZE where applicable. (#5392)

Same behavior, but without our own boilerplate function.
This commit is contained in:
LC 2020-06-19 10:10:45 -04:00 committed by GitHub
parent f7aaa37bf2
commit 8ce81b19be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 35 additions and 29 deletions

View File

@ -373,7 +373,7 @@ GraphicsVertexShaderWidget::GraphicsVertexShaderWidget(
auto input_data_mapper = new QSignalMapper(this);
// TODO: Support inputting data in hexadecimal raw format
for (unsigned i = 0; i < ARRAY_SIZE(input_data); ++i) {
for (std::size_t i = 0; i < input_data.size(); ++i) {
input_data[i] = new QLineEdit;
input_data[i]->setValidator(new QDoubleValidator(input_data[i]));
}
@ -401,7 +401,7 @@ GraphicsVertexShaderWidget::GraphicsVertexShaderWidget(
connect(cycle_index, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
&GraphicsVertexShaderWidget::OnCycleIndexChanged);
for (unsigned i = 0; i < ARRAY_SIZE(input_data); ++i) {
for (u32 i = 0; i < input_data.size(); ++i) {
connect(input_data[i], &QLineEdit::textEdited, input_data_mapper,
static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
input_data_mapper->setMapping(input_data[i], i);

View File

@ -67,13 +67,14 @@ private:
QTreeView* binary_list;
GraphicsVertexShaderModel* model;
/// TODO: Move these into a single struct
std::array<QLineEdit*, 4 * 16>
input_data; // A text box for each of the 4 components of up to 16 vertex attributes
std::array<QWidget*, 16>
input_data_container; // QWidget containing the QLayout containing each vertex attribute
std::array<QLabel*, 16> input_data_mapping; // A QLabel denoting the shader input attribute
// which the vertex attribute maps to
// TODO: Move these into a single struct
// A text box for each of the 4 components of up to 16 vertex attributes
std::array<QLineEdit*, 4 * 16> input_data;
// QWidget containing the QLayout containing each vertex attribute
std::array<QWidget*, 16> input_data_container;
// A QLabel denoting the shader input attribute which the vertex attribute maps to
std::array<QLabel*, 16> input_data_mapping;
// Text to be shown when input vertex data is not retrievable
QLabel* breakpoint_warning;

View File

@ -11,8 +11,6 @@
#endif
#include "common/common_types.h"
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
/// Textually concatenates two tokens. The double-expansion is required by the C preprocessor.
#define CONCAT2(x, y) DO_CONCAT2(x, y)
#define DO_CONCAT2(x, y) x##y

View File

@ -167,12 +167,16 @@ struct ExHeader_ARM11_SystemLocalCaps {
};
struct ExHeader_ARM11_KernelCaps {
u32_le descriptors[28];
static constexpr std::size_t NUM_DESCRIPTORS = 28;
u32_le descriptors[NUM_DESCRIPTORS];
u8 reserved[0x10];
};
struct ExHeader_ARM9_AccessControl {
u8 descriptors[15];
static constexpr std::size_t NUM_DESCRIPTORS = 15;
u8 descriptors[NUM_DESCRIPTORS];
u8 descversion;
};

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#include <algorithm>
#include <array>
#include <cinttypes>
#include <map>
#include <fmt/format.h>
@ -182,7 +183,7 @@ private:
const char* name;
};
static const FunctionDef SVC_Table[];
static const std::array<FunctionDef, 126> SVC_Table;
static const FunctionDef* GetSVCInfo(u32 func_num);
};
@ -1458,7 +1459,7 @@ ResultCode SVC::GetProcessInfo(s64* out, Handle process_handle, u32 type) {
return RESULT_SUCCESS;
}
const SVC::FunctionDef SVC::SVC_Table[] = {
const std::array<SVC::FunctionDef, 126> SVC::SVC_Table{{
{0x00, nullptr, "Unknown"},
{0x01, &SVC::Wrap<&SVC::ControlMemory>, "ControlMemory"},
{0x02, &SVC::Wrap<&SVC::QueryMemory>, "QueryMemory"},
@ -1585,10 +1586,10 @@ const SVC::FunctionDef SVC::SVC_Table[] = {
{0x7B, nullptr, "Backdoor"},
{0x7C, nullptr, "KernelSetState"},
{0x7D, &SVC::Wrap<&SVC::QueryProcessMemory>, "QueryProcessMemory"},
};
}};
const SVC::FunctionDef* SVC::GetSVCInfo(u32 func_num) {
if (func_num >= ARRAY_SIZE(SVC_Table)) {
if (func_num >= SVC_Table.size()) {
LOG_ERROR(Kernel_SVC, "unknown svc=0x{:02X}", func_num);
return nullptr;
}

View File

@ -675,7 +675,7 @@ std::u16string Module::GetUsername() {
// the username string in the block isn't null-terminated,
// so we need to find the end manually.
std::u16string username(block.username, ARRAY_SIZE(block.username));
std::u16string username(block.username, std::size(block.username));
const std::size_t pos = username.find(u'\0');
if (pos != std::u16string::npos)
username.erase(pos);

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <array>
#include <cstring>
#include "common/archives.h"
#include "common/common_funcs.h"
@ -29,12 +30,12 @@ void Y2R_U::serialize(Archive& ar, const unsigned int) {
ar& spacial_dithering_enabled;
}
static const CoefficientSet standard_coefficients[4] = {
constexpr std::array<CoefficientSet, 4> standard_coefficients{{
{{0x100, 0x166, 0xB6, 0x58, 0x1C5, -0x166F, 0x10EE, -0x1C5B}}, // ITU_Rec601
{{0x100, 0x193, 0x77, 0x2F, 0x1DB, -0x1933, 0xA7C, -0x1D51}}, // ITU_Rec709
{{0x12A, 0x198, 0xD0, 0x64, 0x204, -0x1BDE, 0x10F2, -0x229B}}, // ITU_Rec601_Scaling
{{0x12A, 0x1CA, 0x88, 0x36, 0x21C, -0x1F04, 0x99C, -0x2421}}, // ITU_Rec709_Scaling
};
}};
ResultCode ConversionConfiguration::SetInputLineWidth(u16 width) {
if (width == 0 || width > 1024 || width % 8 != 0) {
@ -66,8 +67,8 @@ ResultCode ConversionConfiguration::SetInputLines(u16 lines) {
ResultCode ConversionConfiguration::SetStandardCoefficient(
StandardCoefficient standard_coefficient) {
std::size_t index = static_cast<std::size_t>(standard_coefficient);
if (index >= ARRAY_SIZE(standard_coefficients)) {
const auto index = static_cast<std::size_t>(standard_coefficient);
if (index >= standard_coefficients.size()) {
return ResultCode(ErrorDescription::InvalidEnumValue, ErrorModule::CAM,
ErrorSummary::InvalidArgument, ErrorLevel::Usage); // 0xE0E053ED
}
@ -457,9 +458,9 @@ void Y2R_U::SetStandardCoefficient(Kernel::HLERequestContext& ctx) {
void Y2R_U::GetStandardCoefficient(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x21, 1, 0);
u32 index = rp.Pop<u32>();
const u32 index = rp.Pop<u32>();
if (index < ARRAY_SIZE(standard_coefficients)) {
if (index < standard_coefficients.size()) {
IPC::RequestBuilder rb = rp.MakeBuilder(5, 0);
rb.Push(RESULT_SUCCESS);
rb.PushRaw(standard_coefficients[index]);

View File

@ -134,8 +134,8 @@ ResultStatus AppLoader_NCCH::LoadExec(std::shared_ptr<Kernel::Process>& process)
overlay_ncch->exheader_header.arm11_system_local_caps.ideal_processor;
// Copy data while converting endianness
std::array<u32, ARRAY_SIZE(overlay_ncch->exheader_header.arm11_kernel_caps.descriptors)>
kernel_caps;
using KernelCaps = std::array<u32, ExHeader_ARM11_KernelCaps::NUM_DESCRIPTORS>;
KernelCaps kernel_caps;
std::copy_n(overlay_ncch->exheader_header.arm11_kernel_caps.descriptors, kernel_caps.size(),
begin(kernel_caps));
process->ParseKernelCaps(kernel_caps.data(), kernel_caps.size());

View File

@ -206,7 +206,7 @@ void OpenGLState::Apply() const {
}
// Textures
for (unsigned i = 0; i < ARRAY_SIZE(texture_units); ++i) {
for (u32 i = 0; i < texture_units.size(); ++i) {
if (texture_units[i].texture_2d != cur_state.texture_units[i].texture_2d) {
glActiveTexture(TextureUnits::PicaTexture(i).Enum());
glBindTexture(GL_TEXTURE_2D, texture_units[i].texture_2d);

View File

@ -90,10 +90,11 @@ public:
GLenum logic_op; // GL_LOGIC_OP_MODE
// 3 texture units - one for each that is used in PICA fragment shader emulation
struct {
struct TextureUnit {
GLuint texture_2d; // GL_TEXTURE_BINDING_2D
GLuint sampler; // GL_SAMPLER_BINDING
} texture_units[3];
};
std::array<TextureUnit, 3> texture_units;
struct {
GLuint texture_cube; // GL_TEXTURE_BINDING_CUBE_MAP