From 092fcafd1976d6040844c963377c7fad52d702c0 Mon Sep 17 00:00:00 2001 From: Brackyt <60280126+Brackyt@users.noreply.github.com> Date: Mon, 26 Jan 2026 00:22:05 +0100 Subject: [PATCH] fix(cppcheck): resolve style and performance issues - Remove unused HomeActivity::restoreCoverBuffer - Use initialization lists in constructors - Mark single-argument constructors as explicit --- lib/ThemeEngine/include/BasicElements.h | 29 +++++++++++++------------ lib/ThemeEngine/include/ThemeContext.h | 2 +- lib/ThemeEngine/include/ThemeTypes.h | 2 +- lib/ThemeEngine/include/UIElement.h | 2 +- src/activities/home/HomeActivity.cpp | 13 ----------- src/activities/home/HomeActivity.h | 2 +- 6 files changed, 19 insertions(+), 31 deletions(-) diff --git a/lib/ThemeEngine/include/BasicElements.h b/lib/ThemeEngine/include/BasicElements.h index e167bed8..f0dcae82 100644 --- a/lib/ThemeEngine/include/BasicElements.h +++ b/lib/ThemeEngine/include/BasicElements.h @@ -23,7 +23,7 @@ class Container : public UIElement { int borderRadius = 0; // Corner radius (for future rounded rect support) public: - Container(const std::string& id) : UIElement(id) { bgColorExpr = Expression::parse("0xFF"); } + explicit Container(const std::string& id) : UIElement(id), bgColorExpr(Expression::parse("0xFF")) {} virtual ~Container() { for (auto child : children) delete child; } @@ -145,7 +145,7 @@ class Rectangle : public UIElement { Expression colorExpr; public: - Rectangle(const std::string& id) : UIElement(id) { colorExpr = Expression::parse("0x00"); } + explicit Rectangle(const std::string& id) : UIElement(id), colorExpr(Expression::parse("0x00")) {} ElementType getType() const override { return ElementType::Rectangle; } void setFill(bool f) { @@ -199,7 +199,7 @@ class Label : public UIElement { bool ellipsis = true; // Truncate with ... if too long public: - Label(const std::string& id) : UIElement(id) { colorExpr = Expression::parse("0x00"); } + explicit Label(const std::string& id) : UIElement(id), colorExpr(Expression::parse("0x00")) {} ElementType getType() const override { return ElementType::Label; } void setText(const std::string& expr) { @@ -367,7 +367,7 @@ class BitmapElement : public UIElement { int borderRadius = 0; public: - BitmapElement(const std::string& id) : UIElement(id) { + explicit BitmapElement(const std::string& id) : UIElement(id) { cacheable = true; // Bitmaps benefit from caching } ElementType getType() const override { return ElementType::Bitmap; } @@ -407,12 +407,13 @@ class ProgressBar : public UIElement { int borderWidth = 1; public: - ProgressBar(const std::string& id) : UIElement(id) { - valueExpr = Expression::parse("0"); - maxExpr = Expression::parse("100"); - fgColorExpr = Expression::parse("0x00"); // Black fill - bgColorExpr = Expression::parse("0xFF"); // White background - } + explicit ProgressBar(const std::string& id) + : UIElement(id), + valueExpr(Expression::parse("0")), + maxExpr(Expression::parse("100")), + fgColorExpr(Expression::parse("0x00")), // Black fill + bgColorExpr(Expression::parse("0xFF")) // White background + {} ElementType getType() const override { return ElementType::ProgressBar; } @@ -480,7 +481,7 @@ class Divider : public UIElement { int thickness = 1; public: - Divider(const std::string& id) : UIElement(id) { colorExpr = Expression::parse("0x00"); } + explicit Divider(const std::string& id) : UIElement(id), colorExpr(Expression::parse("0x00")) {} ElementType getType() const override { return ElementType::Divider; } @@ -524,9 +525,9 @@ class BatteryIcon : public UIElement { Expression colorExpr; public: - BatteryIcon(const std::string& id) : UIElement(id) { - valueExpr = Expression::parse("0"); - colorExpr = Expression::parse("0x00"); // Black by default + explicit BatteryIcon(const std::string& id) + : UIElement(id), valueExpr(Expression::parse("0")), colorExpr(Expression::parse("0x00")) { + // Black by default } ElementType getType() const override { return ElementType::BatteryIcon; } diff --git a/lib/ThemeEngine/include/ThemeContext.h b/lib/ThemeEngine/include/ThemeContext.h index 1f03e654..73222a56 100644 --- a/lib/ThemeEngine/include/ThemeContext.h +++ b/lib/ThemeEngine/include/ThemeContext.h @@ -83,7 +83,7 @@ class ThemeContext { } public: - ThemeContext(const ThemeContext* parent = nullptr) : parent(parent) {} + explicit ThemeContext(const ThemeContext* parent = nullptr) : parent(parent) {} void setString(const std::string& key, const std::string& value) { strings[key] = value; } void setInt(const std::string& key, int value) { ints[key] = value; } diff --git a/lib/ThemeEngine/include/ThemeTypes.h b/lib/ThemeEngine/include/ThemeTypes.h index d9d733f6..5c2ada28 100644 --- a/lib/ThemeEngine/include/ThemeTypes.h +++ b/lib/ThemeEngine/include/ThemeTypes.h @@ -34,7 +34,7 @@ struct Dimension { struct Color { uint8_t value; // For E-Ink: 0 (Black) to 255 (White), or simplified palette - Color(uint8_t v) : value(v) {} + explicit Color(uint8_t v) : value(v) {} Color() : value(0) {} static Color parse(const std::string& str) { diff --git a/lib/ThemeEngine/include/UIElement.h b/lib/ThemeEngine/include/UIElement.h index ac53f7ac..6d639fdc 100644 --- a/lib/ThemeEngine/include/UIElement.h +++ b/lib/ThemeEngine/include/UIElement.h @@ -45,7 +45,7 @@ class UIElement { } public: - UIElement(const std::string& id) : id(id) { visibleExpr = Expression::parse("true"); } + UIElement(const std::string& id) : id(id), visibleExpr(Expression::parse("true")) {} virtual ~UIElement() { if (cachedRender) { diff --git a/src/activities/home/HomeActivity.cpp b/src/activities/home/HomeActivity.cpp index a3292a28..6251c535 100644 --- a/src/activities/home/HomeActivity.cpp +++ b/src/activities/home/HomeActivity.cpp @@ -232,20 +232,7 @@ bool HomeActivity::storeCoverBuffer() { return true; } -bool HomeActivity::restoreCoverBuffer() { - if (!coverBuffer) { - return false; - } - uint8_t* frameBuffer = renderer.getFrameBuffer(); - if (!frameBuffer) { - return false; - } - - const size_t bufferSize = GfxRenderer::getBufferSize(); - memcpy(frameBuffer, coverBuffer, bufferSize); - return true; -} void HomeActivity::freeCoverBuffer() { if (coverBuffer) { diff --git a/src/activities/home/HomeActivity.h b/src/activities/home/HomeActivity.h index 64bb89c6..bb9e61d8 100644 --- a/src/activities/home/HomeActivity.h +++ b/src/activities/home/HomeActivity.h @@ -47,7 +47,7 @@ class HomeActivity final : public Activity { void render(); int getMenuItemCount() const; bool storeCoverBuffer(); // Store frame buffer for cover image - bool restoreCoverBuffer(); // Restore frame buffer from stored cover + void freeCoverBuffer(); // Free the stored cover buffer void loadRecentBooksData(); // Load and cache recent books data