From bb4d48fbf9d0ad6be570d9c9b052f835f3a8b0d5 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Sat, 13 Sep 2025 18:20:35 +0300 Subject: fix: Use const references to avoid unnecessary variable copying This commit addresses cppcheck warnings about variables that can be declared as const references (constVariableReference). These variables were being copied unnecessarily when they could be accessed as const references, improving performance and code clarity. Fixed files: - kms++util/src/cpuframebuffer.cpp: Make plane reference const in destructor - kms++util/src/testpat.cpp: Make info and lambda parameter const references - utils/kmstest.cpp: Make loop variable const reference in output parsing --- kms++util/src/cpuframebuffer.cpp | 2 +- kms++util/src/testpat.cpp | 4 ++-- utils/kmstest.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kms++util/src/cpuframebuffer.cpp b/kms++util/src/cpuframebuffer.cpp index 8eac8c4..64ad531 100644 --- a/kms++util/src/cpuframebuffer.cpp +++ b/kms++util/src/cpuframebuffer.cpp @@ -26,7 +26,7 @@ CPUFramebuffer::CPUFramebuffer(uint32_t width, uint32_t height, PixelFormat form CPUFramebuffer::~CPUFramebuffer() { for (unsigned i = 0; i < m_num_planes; ++i) { - FramebufferPlane& plane = m_planes[i]; + const FramebufferPlane& plane = m_planes[i]; delete[] plane.map; } diff --git a/kms++util/src/testpat.cpp b/kms++util/src/testpat.cpp index 1edf978..8444ce0 100644 --- a/kms++util/src/testpat.cpp +++ b/kms++util/src/testpat.cpp @@ -471,7 +471,7 @@ static void draw_test_pattern_part(IFramebuffer& fb, size_t start_y, size_t end_ void draw_test_pattern_multi(IFramebuffer& fb, const TestPatternOptions& options) { - auto& info = get_pixel_format_info(fb.format()); + const auto& info = get_pixel_format_info(fb.format()); uint8_t v_sub = 0; for (size_t p = 0; p < info.num_planes; ++p) v_sub = max(v_sub, info.planes[p].vsub); @@ -514,7 +514,7 @@ void draw_test_pattern_multi(IFramebuffer& fb, const TestPatternOptions& options t.join(); auto i = std::find_if(errors.begin(), errors.end(), - [](auto& e) { return e != nullptr; }); + [](const auto& e) { return e != nullptr; }); if (i != errors.end()) std::rethrow_exception(*i); } diff --git a/utils/kmstest.cpp b/utils/kmstest.cpp index 5028e7e..8340fa7 100644 --- a/utils/kmstest.cpp +++ b/utils/kmstest.cpp @@ -572,7 +572,7 @@ static vector setups_to_outputs(Card& card, ResourceManager& resman, OutputInfo* current_output = 0; PlaneInfo* current_plane = 0; - for (auto& arg : output_args) { + for (const auto& arg : output_args) { switch (arg.type) { case ArgType::Connector: { outputs.push_back(OutputInfo{}); -- cgit v1.2.3