From 365d8c57c79c14783a655a1dd36a621c4ecdee19 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 4 Oct 2018 06:33:17 -0400 Subject: [PATCH] ui_settings: Place definition of the theme array within the cpp file Placing the array wholesale into the header places a copy of the whole array into every translation unit that uses the data, which is wasteful. Particularly given that this array is referenced from three different translation units. This also changes the array to contain pairs of const char*, rather than QString instances. This way, the string data is able to be fixed into the read-only segment of the program, as well as eliminate static constructors/heap allocation immediately on program start. --- src/citra_qt/configuration/configure_general.cpp | 2 +- src/citra_qt/ui_settings.cpp | 10 +++++++++- src/citra_qt/ui_settings.h | 7 ++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/citra_qt/configuration/configure_general.cpp b/src/citra_qt/configuration/configure_general.cpp index d1b04bad7e..33befa7b79 100644 --- a/src/citra_qt/configuration/configure_general.cpp +++ b/src/citra_qt/configuration/configure_general.cpp @@ -31,7 +31,7 @@ ConfigureGeneral::ConfigureGeneral(QWidget* parent) static_cast(&QComboBox::currentIndexChanged), this, &ConfigureGeneral::onLanguageChanged); - for (auto theme : UISettings::themes) { + for (const auto& theme : UISettings::themes) { ui->theme_combobox->addItem(theme.first, theme.second); } diff --git a/src/citra_qt/ui_settings.cpp b/src/citra_qt/ui_settings.cpp index 120b349901..b27fc7661b 100644 --- a/src/citra_qt/ui_settings.cpp +++ b/src/citra_qt/ui_settings.cpp @@ -6,5 +6,13 @@ namespace UISettings { +const Themes themes{{ + {"Default", "default"}, + {"Dark", "qdarkstyle"}, + {"Colorful", "colorful"}, + {"Colorful Dark", "colorful_dark"}, +}}; + Values values = {}; -} + +} // namespace UISettings diff --git a/src/citra_qt/ui_settings.h b/src/citra_qt/ui_settings.h index 1cd94c99da..b36da33410 100644 --- a/src/citra_qt/ui_settings.h +++ b/src/citra_qt/ui_settings.h @@ -16,11 +16,8 @@ namespace UISettings { using ContextualShortcut = std::pair; using Shortcut = std::pair; -static const std::array, 4> themes = { - {std::make_pair(QString("Default"), QString("default")), - std::make_pair(QString("Dark"), QString("qdarkstyle")), - std::make_pair(QString("Colorful"), QString("colorful")), - std::make_pair(QString("Colorful Dark"), QString("colorful_dark"))}}; +using Themes = std::array, 4>; +extern const Themes themes; struct GameDir { QString path;