From 246fd307b6a591f34d237169a0faca61b8c6996a Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Thu, 3 Nov 2022 16:03:21 +0100 Subject: [PATCH] Changed a number of theme properties to be read by reference instead of via copy. --- es-core/src/components/BadgeComponent.cpp | 6 ++-- es-core/src/components/DateTimeComponent.cpp | 34 +++++++++--------- es-core/src/components/GIFAnimComponent.cpp | 6 ++-- .../src/components/GameSelectorComponent.h | 6 ++-- es-core/src/components/ImageComponent.cpp | 8 ++--- .../src/components/LottieAnimComponent.cpp | 2 +- es-core/src/components/RatingComponent.cpp | 4 +-- es-core/src/components/TextComponent.cpp | 36 +++++++++---------- es-core/src/components/VideoComponent.cpp | 4 +-- 9 files changed, 53 insertions(+), 53 deletions(-) diff --git a/es-core/src/components/BadgeComponent.cpp b/es-core/src/components/BadgeComponent.cpp index b5323ce8a..5c0c89f7f 100644 --- a/es-core/src/components/BadgeComponent.cpp +++ b/es-core/src/components/BadgeComponent.cpp @@ -291,7 +291,7 @@ void BadgeComponent::applyTheme(const std::shared_ptr& theme, if (elem->has("slots")) { // Replace possible whitespace separators with commas. - std::string slotsTag = Utils::String::toLower(elem->get("slots")); + std::string slotsTag {Utils::String::toLower(elem->get("slots"))}; for (auto& character : slotsTag) { if (std::isspace(character)) character = ','; @@ -312,7 +312,7 @@ void BadgeComponent::applyTheme(const std::shared_ptr& theme, // The "badge_" string is required as ThemeData adds this as a prefix to avoid // name collisions when using XML attributes. if (properties & PATH && elem->has("badge_" + slot)) { - const std::string path {elem->get("badge_" + slot)}; + const std::string& path {elem->get("badge_" + slot)}; if (Utils::FileSystem::exists(path) && !Utils::FileSystem::isDirectory(path)) { mBadgeIcons[slot] = path; } @@ -385,7 +385,7 @@ void BadgeComponent::applyTheme(const std::shared_ptr& theme, for (auto& gameController : sGameControllers) { if (properties & PATH && elem->has("controller_" + gameController.shortName)) { - const std::string path { + const std::string& path { elem->get("controller_" + gameController.shortName)}; if (Utils::FileSystem::exists(path) && !Utils::FileSystem::isDirectory(path)) { gameController.fileName = path; diff --git a/es-core/src/components/DateTimeComponent.cpp b/es-core/src/components/DateTimeComponent.cpp index ed4dfb27e..272cb2da8 100644 --- a/es-core/src/components/DateTimeComponent.cpp +++ b/es-core/src/components/DateTimeComponent.cpp @@ -130,51 +130,51 @@ void DateTimeComponent::applyTheme(const std::shared_ptr& theme, } if (properties & ALIGNMENT && elem->has("horizontalAlignment")) { - std::string str {elem->get("horizontalAlignment")}; - if (str == "left") + const std::string& horizontalAlignment {elem->get("horizontalAlignment")}; + if (horizontalAlignment == "left") setHorizontalAlignment(ALIGN_LEFT); - else if (str == "center") + else if (horizontalAlignment == "center") setHorizontalAlignment(ALIGN_CENTER); - else if (str == "right") + else if (horizontalAlignment == "right") setHorizontalAlignment(ALIGN_RIGHT); else LOG(LogWarning) << "DateTimeComponent: Invalid theme configuration, property " " defined as \"" - << str << "\""; + << horizontalAlignment << "\""; } if (properties & ALIGNMENT && elem->has("verticalAlignment")) { - std::string str {elem->get("verticalAlignment")}; - if (str == "top") + const std::string& verticalAlignment {elem->get("verticalAlignment")}; + if (verticalAlignment == "top") setVerticalAlignment(ALIGN_TOP); - else if (str == "center") + else if (verticalAlignment == "center") setVerticalAlignment(ALIGN_CENTER); - else if (str == "bottom") + else if (verticalAlignment == "bottom") setVerticalAlignment(ALIGN_BOTTOM); else LOG(LogWarning) << "DateTimeComponent: Invalid theme configuration, property " " defined as \"" - << str << "\""; + << verticalAlignment << "\""; } // Legacy themes only. if (properties & ALIGNMENT && elem->has("alignment")) { - std::string str {elem->get("alignment")}; - if (str == "left") + const std::string& alignment {elem->get("alignment")}; + if (alignment == "left") setHorizontalAlignment(ALIGN_LEFT); - else if (str == "center") + else if (alignment == "center") setHorizontalAlignment(ALIGN_CENTER); - else if (str == "right") + else if (alignment == "right") setHorizontalAlignment(ALIGN_RIGHT); else LOG(LogWarning) << "DateTimeComponent: Invalid theme configuration, property " " defined as \"" - << str << "\""; + << alignment << "\""; } if (properties & METADATA && elem->has("metadata")) { mThemeMetadata = ""; - const std::string metadata {elem->get("metadata")}; + const std::string& metadata {elem->get("metadata")}; if (metadata == "releasedate" || metadata == "lastplayed") { mThemeMetadata = metadata; } @@ -192,7 +192,7 @@ void DateTimeComponent::applyTheme(const std::shared_ptr& theme, setDisplayRelative(elem->get("displayRelative")); if (properties & LETTER_CASE && elem->has("letterCase")) { - std::string letterCase {elem->get("letterCase")}; + const std::string& letterCase {elem->get("letterCase")}; if (letterCase == "uppercase") { setUppercase(true); } diff --git a/es-core/src/components/GIFAnimComponent.cpp b/es-core/src/components/GIFAnimComponent.cpp index 7386f5cb2..ccadfcb03 100644 --- a/es-core/src/components/GIFAnimComponent.cpp +++ b/es-core/src/components/GIFAnimComponent.cpp @@ -286,7 +286,7 @@ void GIFAnimComponent::applyTheme(const std::shared_ptr& theme, mKeepAspectRatio = elem->get("keepAspectRatio"); if (elem->has("direction")) { - std::string direction = elem->get("direction"); + const std::string& direction {elem->get("direction")}; if (direction == "normal") { mStartDirection = "normal"; mAlternate = false; @@ -313,7 +313,7 @@ void GIFAnimComponent::applyTheme(const std::shared_ptr& theme, } if (elem->has("interpolation")) { - const std::string interpolation {elem->get("interpolation")}; + const std::string& interpolation {elem->get("interpolation")}; if (interpolation == "linear") { mTexture->setLinearMagnify(true); } @@ -332,7 +332,7 @@ void GIFAnimComponent::applyTheme(const std::shared_ptr& theme, GuiComponent::applyTheme(theme, view, element, properties); if (elem->has("path")) { - std::string path {elem->get("path")}; + const std::string& path {elem->get("path")}; if (path != "") { setAnimation(path); } diff --git a/es-core/src/components/GameSelectorComponent.h b/es-core/src/components/GameSelectorComponent.h index c08eb8747..b08ffcc5a 100644 --- a/es-core/src/components/GameSelectorComponent.h +++ b/es-core/src/components/GameSelectorComponent.h @@ -123,7 +123,7 @@ public: mSelectorName = element.substr(13, std::string::npos); if (elem->has("selection")) { - const std::string selection {elem->get("selection")}; + const std::string& selection {elem->get("selection")}; if (selection == "random") { mGameSelection = GameSelection::RANDOM; } @@ -140,8 +140,8 @@ public: else { mGameSelection = GameSelection::RANDOM; LOG(LogWarning) << "GameSelectorComponent: Invalid theme configuration, property " - " defined as \"" - << selection << "\""; + "\"selection\" for element \"" + << element.substr(13) << "\" defined as \"" << selection << "\""; } } diff --git a/es-core/src/components/ImageComponent.cpp b/es-core/src/components/ImageComponent.cpp index b580b726f..fd9c142c4 100644 --- a/es-core/src/components/ImageComponent.cpp +++ b/es-core/src/components/ImageComponent.cpp @@ -433,7 +433,7 @@ void ImageComponent::applyTheme(const std::shared_ptr& theme, } if (elem->has("interpolation")) { - const std::string interpolation {elem->get("interpolation")}; + const std::string& interpolation {elem->get("interpolation")}; if (interpolation == "linear") { mLinearInterpolation = true; } @@ -454,7 +454,7 @@ void ImageComponent::applyTheme(const std::shared_ptr& theme, bool tile {elem->has("tile") && elem->get("tile")}; if (properties & PATH && elem->has("path")) { - const std::string path {elem->get("path")}; + const std::string& path {elem->get("path")}; if (tile && elem->has("tileSize")) { glm::vec2 tileSize {elem->get("tileSize")}; @@ -479,7 +479,7 @@ void ImageComponent::applyTheme(const std::shared_ptr& theme, bool updateAlignment {false}; if (elem->has("tileHorizontalAlignment")) { - const std::string alignment {elem->get("tileHorizontalAlignment")}; + const std::string& alignment {elem->get("tileHorizontalAlignment")}; updateAlignment = true; if (alignment == "left") { mTileHorizontalAlignment = ALIGN_LEFT; @@ -496,7 +496,7 @@ void ImageComponent::applyTheme(const std::shared_ptr& theme, } if (elem->has("tileVerticalAlignment")) { - const std::string alignment {elem->get("tileVerticalAlignment")}; + const std::string& alignment {elem->get("tileVerticalAlignment")}; updateAlignment = true; if (alignment == "top") { mTileVerticalAlignment = ALIGN_TOP; diff --git a/es-core/src/components/LottieAnimComponent.cpp b/es-core/src/components/LottieAnimComponent.cpp index c170c752f..fe32254c8 100644 --- a/es-core/src/components/LottieAnimComponent.cpp +++ b/es-core/src/components/LottieAnimComponent.cpp @@ -256,7 +256,7 @@ void LottieAnimComponent::applyTheme(const std::shared_ptr& theme, mKeepAspectRatio = elem->get("keepAspectRatio"); if (elem->has("direction")) { - std::string direction = elem->get("direction"); + const std::string& direction {elem->get("direction")}; if (direction == "normal") { mStartDirection = "normal"; mAlternate = false; diff --git a/es-core/src/components/RatingComponent.cpp b/es-core/src/components/RatingComponent.cpp index 362c0e794..a63d98d24 100644 --- a/es-core/src/components/RatingComponent.cpp +++ b/es-core/src/components/RatingComponent.cpp @@ -180,7 +180,7 @@ void RatingComponent::applyTheme(const std::shared_ptr& theme, // Read the image file in order to retrieve the image dimensions needed to calculate // the aspect ratio constant. if (properties & PATH && elem->has("filledPath")) { - std::string path {std::string(elem->get("filledPath"))}; + const std::string& path {std::string(elem->get("filledPath"))}; if (Utils::FileSystem::isRegularFile(path) || Utils::FileSystem::isSymlink(path)) { auto tempImage = TextureResource::get(path, false, false, false, false, false, 0, 0, 0.0f, 0.0f); @@ -212,7 +212,7 @@ void RatingComponent::applyTheme(const std::shared_ptr& theme, bool linearInterpolation {false}; if (elem->has("interpolation")) { - const std::string interpolation {elem->get("interpolation")}; + const std::string& interpolation {elem->get("interpolation")}; if (interpolation == "linear") { linearInterpolation = true; } diff --git a/es-core/src/components/TextComponent.cpp b/es-core/src/components/TextComponent.cpp index fcab0a511..d392d0ed7 100644 --- a/es-core/src/components/TextComponent.cpp +++ b/es-core/src/components/TextComponent.cpp @@ -378,49 +378,49 @@ void TextComponent::applyTheme(const std::shared_ptr& theme, } if (properties & ALIGNMENT && elem->has("horizontalAlignment")) { - std::string str {elem->get("horizontalAlignment")}; - if (str == "left") + const std::string& horizontalAlignment {elem->get("horizontalAlignment")}; + if (horizontalAlignment == "left") setHorizontalAlignment(ALIGN_LEFT); - else if (str == "center") + else if (horizontalAlignment == "center") setHorizontalAlignment(ALIGN_CENTER); - else if (str == "right") + else if (horizontalAlignment == "right") setHorizontalAlignment(ALIGN_RIGHT); else LOG(LogWarning) << componentName << ": Invalid theme configuration, property " " defined as \"" - << str << "\""; + << horizontalAlignment << "\""; } if (properties & ALIGNMENT && elem->has("verticalAlignment")) { - std::string str {elem->get("verticalAlignment")}; - if (str == "top") + const std::string& verticalAlignment {elem->get("verticalAlignment")}; + if (verticalAlignment == "top") setVerticalAlignment(ALIGN_TOP); - else if (str == "center") + else if (verticalAlignment == "center") setVerticalAlignment(ALIGN_CENTER); - else if (str == "bottom") + else if (verticalAlignment == "bottom") setVerticalAlignment(ALIGN_BOTTOM); else LOG(LogWarning) << componentName << ": Invalid theme configuration, property " " defined as \"" - << str << "\""; + << verticalAlignment << "\""; } // Legacy themes only. if (properties & ALIGNMENT && elem->has("alignment")) { - std::string str {elem->get("alignment")}; - if (str == "left") + const std::string& alignment {elem->get("alignment")}; + if (alignment == "left") setHorizontalAlignment(ALIGN_LEFT); - else if (str == "center") + else if (alignment == "center") setHorizontalAlignment(ALIGN_CENTER); - else if (str == "right") + else if (alignment == "right") setHorizontalAlignment(ALIGN_RIGHT); else LOG(LogWarning) << componentName << ": Invalid theme configuration, property " " defined as \"" - << str << "\""; + << alignment << "\""; } if (properties & TEXT && elem->has("text")) @@ -428,7 +428,7 @@ void TextComponent::applyTheme(const std::shared_ptr& theme, if (properties & METADATA && elem->has("systemdata")) { mThemeSystemdata = ""; - const std::string systemdata {elem->get("systemdata")}; + const std::string& systemdata {elem->get("systemdata")}; for (auto& type : supportedSystemdataTypes) { if (type == systemdata) { mThemeSystemdata = type; @@ -444,7 +444,7 @@ void TextComponent::applyTheme(const std::shared_ptr& theme, if (properties & METADATA && elem->has("metadata")) { mThemeMetadata = ""; - const std::string metadata {elem->get("metadata")}; + const std::string& metadata {elem->get("metadata")}; for (auto& type : supportedMetadataTypes) { if (type == metadata) { @@ -460,7 +460,7 @@ void TextComponent::applyTheme(const std::shared_ptr& theme, } if (properties & LETTER_CASE && elem->has("letterCase")) { - std::string letterCase {elem->get("letterCase")}; + const std::string& letterCase {elem->get("letterCase")}; if (letterCase == "uppercase") { setUppercase(true); } diff --git a/es-core/src/components/VideoComponent.cpp b/es-core/src/components/VideoComponent.cpp index 4cb76b6c5..5bde60c27 100644 --- a/es-core/src/components/VideoComponent.cpp +++ b/es-core/src/components/VideoComponent.cpp @@ -155,7 +155,7 @@ void VideoComponent::applyTheme(const std::shared_ptr& theme, mPlayAudio = elem->get("audio"); if (elem->has("interpolation")) { - const std::string interpolation {elem->get("interpolation")}; + const std::string& interpolation {elem->get("interpolation")}; if (interpolation == "linear") { mStaticImage.setLinearInterpolation(true); } @@ -189,7 +189,7 @@ void VideoComponent::applyTheme(const std::shared_ptr& theme, } if (elem->has("path")) { - const std::string staticPath {elem->get("path")}; + const std::string& staticPath {elem->get("path")}; if (ResourceManager::getInstance().fileExists(staticPath)) { mConfig.staticVideoPath = staticPath; }