From 8ce81b19be1a9161c829aec4e0a9521fa8aef57d Mon Sep 17 00:00:00 2001 From: LC Date: Fri, 19 Jun 2020 10:10:45 -0400 Subject: [PATCH] General: Remove usages of ARRAY_SIZE where applicable. (#5392) Same behavior, but without our own boilerplate function. --- .../debugger/graphics/graphics_vertex_shader.cpp | 4 ++-- .../debugger/graphics/graphics_vertex_shader.h | 15 ++++++++------- src/common/common_funcs.h | 2 -- src/core/file_sys/ncch_container.h | 8 ++++++-- src/core/hle/kernel/svc.cpp | 9 +++++---- src/core/hle/service/cfg/cfg.cpp | 2 +- src/core/hle/service/y2r_u.cpp | 13 +++++++------ src/core/loader/ncch.cpp | 4 ++-- src/video_core/renderer_opengl/gl_state.cpp | 2 +- src/video_core/renderer_opengl/gl_state.h | 5 +++-- 10 files changed, 35 insertions(+), 29 deletions(-) diff --git a/src/citra_qt/debugger/graphics/graphics_vertex_shader.cpp b/src/citra_qt/debugger/graphics/graphics_vertex_shader.cpp index e01e09adc..91695f43a 100644 --- a/src/citra_qt/debugger/graphics/graphics_vertex_shader.cpp +++ b/src/citra_qt/debugger/graphics/graphics_vertex_shader.cpp @@ -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(&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(&QSignalMapper::map)); input_data_mapper->setMapping(input_data[i], i); diff --git a/src/citra_qt/debugger/graphics/graphics_vertex_shader.h b/src/citra_qt/debugger/graphics/graphics_vertex_shader.h index c249a2ff8..aeb827c3a 100644 --- a/src/citra_qt/debugger/graphics/graphics_vertex_shader.h +++ b/src/citra_qt/debugger/graphics/graphics_vertex_shader.h @@ -67,13 +67,14 @@ private: QTreeView* binary_list; GraphicsVertexShaderModel* model; - /// TODO: Move these into a single struct - std::array - input_data; // A text box for each of the 4 components of up to 16 vertex attributes - std::array - input_data_container; // QWidget containing the QLayout containing each vertex attribute - std::array 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 input_data; + // QWidget containing the QLayout containing each vertex attribute + std::array input_data_container; + // A QLabel denoting the shader input attribute which the vertex attribute maps to + std::array input_data_mapping; // Text to be shown when input vertex data is not retrievable QLabel* breakpoint_warning; diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index 71a0ec08a..baf145901 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h @@ -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 diff --git a/src/core/file_sys/ncch_container.h b/src/core/file_sys/ncch_container.h index fa435cee0..484218636 100644 --- a/src/core/file_sys/ncch_container.h +++ b/src/core/file_sys/ncch_container.h @@ -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; }; diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index ee0eae626..a2c74e02f 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include #include @@ -182,7 +183,7 @@ private: const char* name; }; - static const FunctionDef SVC_Table[]; + static const std::array 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::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; } diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index 2b1113b92..f9b647cb8 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp @@ -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); diff --git a/src/core/hle/service/y2r_u.cpp b/src/core/hle/service/y2r_u.cpp index 89da8058c..92a46de44 100644 --- a/src/core/hle/service/y2r_u.cpp +++ b/src/core/hle/service/y2r_u.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include #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 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(standard_coefficient); - if (index >= ARRAY_SIZE(standard_coefficients)) { + const auto index = static_cast(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(); + const u32 index = rp.Pop(); - 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]); diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index 81053524f..b2efe0198 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp @@ -134,8 +134,8 @@ ResultStatus AppLoader_NCCH::LoadExec(std::shared_ptr& process) overlay_ncch->exheader_header.arm11_system_local_caps.ideal_processor; // Copy data while converting endianness - std::arrayexheader_header.arm11_kernel_caps.descriptors)> - kernel_caps; + using KernelCaps = std::array; + 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()); diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp index 3e15d64b9..95ab8525a 100644 --- a/src/video_core/renderer_opengl/gl_state.cpp +++ b/src/video_core/renderer_opengl/gl_state.cpp @@ -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); diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h index cc7a864a2..3fa585b04 100644 --- a/src/video_core/renderer_opengl/gl_state.h +++ b/src/video_core/renderer_opengl/gl_state.h @@ -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 texture_units; struct { GLuint texture_cube; // GL_TEXTURE_BINDING_CUBE_MAP