mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 09:40:04 +00:00 
			
		
		
		
	Make sure unordered map references aren't invalidated by reserving sufficient space
This commit is contained in:
		
							parent
							
								
									26a22d4e84
								
							
						
					
					
						commit
						8f4325f61a
					
				
					 7 changed files with 39 additions and 4 deletions
				
			
		|  | @ -57,7 +57,10 @@ public: | ||||||
|                    config::CountyDatabase::GetCountyName(value) != value; |                    config::CountyDatabase::GetCountyName(value) != value; | ||||||
|          }); |          }); | ||||||
| 
 | 
 | ||||||
|       for (auto& phenomenon : types::GetAlertAudioPhenomena()) |       auto& alertAudioPhenomena = types::GetAlertAudioPhenomena(); | ||||||
|  |       alertEnabled_.reserve(alertAudioPhenomena.size() + 1); | ||||||
|  | 
 | ||||||
|  |       for (auto& phenomenon : alertAudioPhenomena) | ||||||
|       { |       { | ||||||
|          std::string phenomenonCode = awips::GetPhenomenonCode(phenomenon); |          std::string phenomenonCode = awips::GetPhenomenonCode(phenomenon); | ||||||
|          std::string name           = fmt::format("{}_enabled", phenomenonCode); |          std::string name           = fmt::format("{}_enabled", phenomenonCode); | ||||||
|  |  | ||||||
|  | @ -50,6 +50,8 @@ class HotkeySettings::Impl | ||||||
| public: | public: | ||||||
|    explicit Impl() |    explicit Impl() | ||||||
|    { |    { | ||||||
|  |       hotkey_.reserve(types::HotkeyIterator().count() + 1); | ||||||
|  | 
 | ||||||
|       for (const auto& hotkey : types::HotkeyIterator()) |       for (const auto& hotkey : types::HotkeyIterator()) | ||||||
|       { |       { | ||||||
|          const std::string& name = types::GetHotkeyShortName(hotkey); |          const std::string& name = types::GetHotkeyShortName(hotkey); | ||||||
|  |  | ||||||
|  | @ -78,6 +78,8 @@ class PaletteSettings::Impl | ||||||
| public: | public: | ||||||
|    explicit Impl() |    explicit Impl() | ||||||
|    { |    { | ||||||
|  |       palette_.reserve(kPaletteKeys_.size()); | ||||||
|  | 
 | ||||||
|       for (const auto& name : kPaletteKeys_) |       for (const auto& name : kPaletteKeys_) | ||||||
|       { |       { | ||||||
|          const std::string& defaultValue = kDefaultPalettes_.at(name); |          const std::string& defaultValue = kDefaultPalettes_.at(name); | ||||||
|  | @ -92,6 +94,9 @@ public: | ||||||
|          variables_.push_back(&settingsVariable); |          variables_.push_back(&settingsVariable); | ||||||
|       }; |       }; | ||||||
| 
 | 
 | ||||||
|  |       activeAlertColor_.reserve(kAlertColors_.size()); | ||||||
|  |       inactiveAlertColor_.reserve(kAlertColors_.size()); | ||||||
|  | 
 | ||||||
|       for (auto& alert : kAlertColors_) |       for (auto& alert : kAlertColors_) | ||||||
|       { |       { | ||||||
|          std::string phenomenonCode = awips::GetPhenomenonCode(alert.first); |          std::string phenomenonCode = awips::GetPhenomenonCode(alert.first); | ||||||
|  |  | ||||||
|  | @ -122,6 +122,8 @@ TextSettings& TextSettings::operator=(TextSettings&&) noexcept = default; | ||||||
| 
 | 
 | ||||||
| void TextSettings::Impl::InitializeFontVariables() | void TextSettings::Impl::InitializeFontVariables() | ||||||
| { | { | ||||||
|  |    fontData_.reserve(types::FontCategoryIterator().count()); | ||||||
|  | 
 | ||||||
|    for (auto fontCategory : types::FontCategoryIterator()) |    for (auto fontCategory : types::FontCategoryIterator()) | ||||||
|    { |    { | ||||||
|       auto  result = fontData_.emplace(fontCategory, FontData {}); |       auto  result = fontData_.emplace(fontCategory, FontData {}); | ||||||
|  |  | ||||||
|  | @ -46,6 +46,8 @@ public: | ||||||
| 
 | 
 | ||||||
|       int row = 0; |       int row = 0; | ||||||
| 
 | 
 | ||||||
|  |       hotkeys_.reserve(types::HotkeyIterator().count()); | ||||||
|  | 
 | ||||||
|       for (types::Hotkey hotkey : types::HotkeyIterator()) |       for (types::Hotkey hotkey : types::HotkeyIterator()) | ||||||
|       { |       { | ||||||
|          const std::string& labelText = types::GetHotkeyLongName(hotkey); |          const std::string& labelText = types::GetHotkeyLongName(hotkey); | ||||||
|  |  | ||||||
|  | @ -658,6 +658,8 @@ void SettingsDialogImpl::SetupPalettesColorTablesTab() | ||||||
|    QGridLayout* colorTableLayout = |    QGridLayout* colorTableLayout = | ||||||
|       reinterpret_cast<QGridLayout*>(self_->ui->colorTableContents->layout()); |       reinterpret_cast<QGridLayout*>(self_->ui->colorTableContents->layout()); | ||||||
| 
 | 
 | ||||||
|  |    colorTables_.reserve(kColorTableTypes_.size()); | ||||||
|  | 
 | ||||||
|    int colorTableRow = 0; |    int colorTableRow = 0; | ||||||
|    for (auto& colorTableType : kColorTableTypes_) |    for (auto& colorTableType : kColorTableTypes_) | ||||||
|    { |    { | ||||||
|  | @ -764,8 +766,13 @@ void SettingsDialogImpl::SetupPalettesAlertsTab() | ||||||
|    alertsLayout->addWidget(activeLabel, 0, 1, 1, 4); |    alertsLayout->addWidget(activeLabel, 0, 1, 1, 4); | ||||||
|    alertsLayout->addWidget(inactiveLabel, 0, 5, 1, 4); |    alertsLayout->addWidget(inactiveLabel, 0, 5, 1, 4); | ||||||
| 
 | 
 | ||||||
|  |    auto& alertPhenomena = settings::PaletteSettings::alert_phenomena(); | ||||||
|  | 
 | ||||||
|  |    activeAlertColors_.reserve(alertPhenomena.size()); | ||||||
|  |    inactiveAlertColors_.reserve(alertPhenomena.size()); | ||||||
|  | 
 | ||||||
|    int alertsRow = 1; |    int alertsRow = 1; | ||||||
|    for (auto& phenomenon : settings::PaletteSettings::alert_phenomena()) |    for (auto& phenomenon : alertPhenomena) | ||||||
|    { |    { | ||||||
|       QFrame* activeFrame   = new QFrame(self_); |       QFrame* activeFrame   = new QFrame(self_); | ||||||
|       QFrame* inactiveFrame = new QFrame(self_); |       QFrame* inactiveFrame = new QFrame(self_); | ||||||
|  | @ -963,10 +970,13 @@ void SettingsDialogImpl::SetupAudioTab() | ||||||
|    alertAudioLongitude_.SetResetButton( |    alertAudioLongitude_.SetResetButton( | ||||||
|       self_->ui->resetAlertAudioLongitudeButton); |       self_->ui->resetAlertAudioLongitudeButton); | ||||||
| 
 | 
 | ||||||
|    auto alertAudioLayout = |    auto& alertAudioPhenomena = types::GetAlertAudioPhenomena(); | ||||||
|  |    auto  alertAudioLayout = | ||||||
|       static_cast<QGridLayout*>(self_->ui->alertAudioGroupBox->layout()); |       static_cast<QGridLayout*>(self_->ui->alertAudioGroupBox->layout()); | ||||||
| 
 | 
 | ||||||
|    for (const auto& phenomenon : types::GetAlertAudioPhenomena()) |    alertAudioEnabled_.reserve(alertAudioPhenomena.size()); | ||||||
|  | 
 | ||||||
|  |    for (const auto& phenomenon : alertAudioPhenomena) | ||||||
|    { |    { | ||||||
|       QCheckBox* alertAudioCheckbox = new QCheckBox(self_); |       QCheckBox* alertAudioCheckbox = new QCheckBox(self_); | ||||||
|       alertAudioCheckbox->setText( |       alertAudioCheckbox->setText( | ||||||
|  | @ -1062,6 +1072,12 @@ void SettingsDialogImpl::SetupTextTab() | ||||||
|    settings::TextSettings& textSettings = settings::TextSettings::Instance(); |    settings::TextSettings& textSettings = settings::TextSettings::Instance(); | ||||||
| 
 | 
 | ||||||
|    self_->ui->fontListView->setModel(fontCategoryModel_); |    self_->ui->fontListView->setModel(fontCategoryModel_); | ||||||
|  | 
 | ||||||
|  |    const auto fontCategoryCount = types::FontCategoryIterator().count(); | ||||||
|  |    fontFamilies_.reserve(fontCategoryCount); | ||||||
|  |    fontStyles_.reserve(fontCategoryCount); | ||||||
|  |    fontPointSizes_.reserve(fontCategoryCount); | ||||||
|  | 
 | ||||||
|    for (const auto& fontCategory : types::FontCategoryIterator()) |    for (const auto& fontCategory : types::FontCategoryIterator()) | ||||||
|    { |    { | ||||||
|       // Add font category to list view
 |       // Add font category to list view
 | ||||||
|  |  | ||||||
|  | @ -28,6 +28,11 @@ public: | ||||||
|       static const Iterator endIterator = ++Iterator(endValue); |       static const Iterator endIterator = ++Iterator(endValue); | ||||||
|       return endIterator; |       return endIterator; | ||||||
|    } |    } | ||||||
|  |    std::size_t count() | ||||||
|  |    { | ||||||
|  |       return static_cast<value_t>(endValue) - static_cast<value_t>(beginValue) + | ||||||
|  |              1; | ||||||
|  |    } | ||||||
|    bool operator!=(const Iterator& i) { return value_ != i.value_; } |    bool operator!=(const Iterator& i) { return value_ != i.value_; } | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat