QmlDesigner: Remove lookups in DSThemeGroup

Multiple lookups on the same key for unchanged maps are not needed.

Change-Id: I1c62bcaf688c165fa970ae94c684f0710a8fdc57
Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
This commit is contained in:
Marco Bubke
2025-01-02 15:22:29 +01:00
parent 59928415b2
commit 3aa10944a1

View File

@@ -61,30 +61,25 @@ bool DSThemeGroup::addProperty(ThemeId theme, const ThemeProperty &prop)
return false; return false;
} }
if (!m_values.contains(prop.name)) auto [valuesIterator, i] = m_values.try_emplace(prop.name);
m_values[prop.name] = {};
auto &tValues = m_values.at(prop.name); auto &tValues = valuesIterator->second;
if (tValues.contains(theme)) { auto [iter, inserted] = tValues.try_emplace(theme, prop.value, prop.isBinding);
if (!inserted)
qCDebug(dsLog) << "Add property failed. Duplicate property name." << prop; qCDebug(dsLog) << "Add property failed. Duplicate property name." << prop;
return false;
}
tValues.emplace(std::piecewise_construct, return inserted;
std::forward_as_tuple(theme),
std::forward_as_tuple(prop.value, prop.isBinding));
return true;
} }
std::optional<ThemeProperty> DSThemeGroup::propertyValue(ThemeId theme, const PropertyName &name) const std::optional<ThemeProperty> DSThemeGroup::propertyValue(ThemeId theme, const PropertyName &name) const
{ {
if (!m_values.contains(name)) const auto valuesIter = m_values.find(name);
if (valuesIter == m_values.end())
return {}; return {};
const auto &tValues = m_values.at(name); const auto &tValues = valuesIter->second;
const auto itr = tValues.find(theme);
if (itr != tValues.end()) { if (const auto itr = tValues.find(theme); itr != tValues.end()) {
auto &[value, isBindind] = itr->second; auto &[value, isBindind] = itr->second;
return ThemeProperty{name, value, isBindind}; return ThemeProperty{name, value, isBindind};
} }
@@ -98,24 +93,25 @@ bool DSThemeGroup::hasProperty(const PropertyName &name) const
bool DSThemeGroup::updateProperty(ThemeId theme, const ThemeProperty &prop) bool DSThemeGroup::updateProperty(ThemeId theme, const ThemeProperty &prop)
{ {
if (!m_values.contains(prop.name)) {
qCDebug(dsLog) << "Property update failure. Can't find property" << prop;
return false;
}
if (!prop.isValid()) { if (!prop.isValid()) {
qCDebug(dsLog) << "Property update failure. Invalid property" << prop; qCDebug(dsLog) << "Property update failure. Invalid property" << prop;
return false; return false;
} }
auto &tValues = m_values.at(prop.name); const auto valuesIter = m_values.find(prop.name);
if (valuesIter == m_values.end()) {
qCDebug(dsLog) << "Property update failure. Can't find property" << prop;
return false;
}
auto &tValues = valuesIter->second;
const auto itr = tValues.find(theme); const auto itr = tValues.find(theme);
if (itr == tValues.end()) { if (itr == tValues.end()) {
qCDebug(dsLog) << "Property update failure. No property for the theme" << theme << prop; qCDebug(dsLog) << "Property update failure. No property for the theme" << theme << prop;
return false; return false;
} }
auto &entry = tValues.at(theme); auto &entry = itr->second;
entry.value = prop.value; entry.value = prop.value;
entry.isBinding = prop.isBinding; entry.isBinding = prop.isBinding;
return true; return true;