Preallocate enough vectors for common app settings #1535

This commit is contained in:
Mark Thompson 2023-10-30 05:32:01 -05:00 committed by GitHub
parent 0bacb31d17
commit a11929d2ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -250,7 +250,7 @@ SettingsManager::SettingsManager(
settings_.options = options; settings_.options = options;
// Pre-alloc enough for app settings and additional settings. // Pre-alloc enough for app settings and additional settings.
additional_settings.reserve(17 + additional_settings.size()); additional_settings.reserve(COMMON_APP_SETTINGS_COUNT + additional_settings.size());
bindings_ = std::move(additional_settings); bindings_ = std::move(additional_settings);
// Settings should always be loaded because apps now rely // Settings should always be loaded because apps now rely

View File

@ -42,6 +42,8 @@
// Bring in the string_view literal. // Bring in the string_view literal.
using std::literals::operator""sv; using std::literals::operator""sv;
#define COMMON_APP_SETTINGS_COUNT 19
/* Represents a named setting bound to a variable instance. */ /* Represents a named setting bound to a variable instance. */
/* Using void* instead of std::variant, because variant is a pain to dispatch over. */ /* Using void* instead of std::variant, because variant is a pain to dispatch over. */
class BoundSetting { class BoundSetting {
@ -143,8 +145,8 @@ struct AppSettings {
uint8_t nbfm_config_index = 0; uint8_t nbfm_config_index = 0;
uint8_t wfm_config_index = 0; uint8_t wfm_config_index = 0;
uint8_t squelch = 80; uint8_t squelch = 80;
uint8_t volume; uint8_t volume;
// NOTE: update COMMON_APP_SETTINGS_COUNT when adding to this
}; };
/* Copies common values to the receiver/transmitter models. */ /* Copies common values to the receiver/transmitter models. */