mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-08-01 09:04:13 +02:00
Replace hash.keys().contains(k) with hash.contains(k) (35 call sites)
QHash/QMap::keys() allocates a list of every key on each call, then contains() searches it linearly - an accidental O(n) plus allocation where a direct O(1) lookup was meant. 35 occurrences across 7 files, found while profiling project load times (context: #553/#560). The hot one is ElementPictureFactory::getPictures(), which runs once per element instance on project load: on the 3399 KiB example project (191 instances, 129 cache hits) the keys() detour cost 45 ms of the 1.34 s total - measured, not estimated; the fix reproducibly shaves ~35-45 ms off that load. The remaining call sites are UI paths (search&replace, dynamic text model, undo commands) where the waste scales with selection/model size. No behavior change: for QHash/QMap, keys().contains(k) and contains(k) are equivalent by definition. (cherry picked from commit 0a7f8f072fa68de7c01a9fc134a4bc8e16d62062)
This commit is contained in:
@@ -419,7 +419,7 @@ void ProjectAutoNumConfigPage::saveContextElement()
|
||||
m_saw_element->contextComboBox()->addItem(tr("Sans nom"));
|
||||
}
|
||||
// If the text isn't yet to the autonum of the project, add this new item to the combo box.
|
||||
else if ( !m_project -> elementAutoNum().keys().contains( m_saw_element->contextComboBox()->currentText()))
|
||||
else if ( !m_project -> elementAutoNum().contains( m_saw_element->contextComboBox()->currentText()))
|
||||
{
|
||||
m_project->addElementAutoNum(m_saw_element->contextComboBox()->currentText(), m_saw_element->toNumContext());
|
||||
m_project->setCurrrentElementAutonum(m_saw_element->contextComboBox()->currentText());
|
||||
@@ -461,7 +461,7 @@ void ProjectAutoNumConfigPage::saveContextConductor()
|
||||
m_saw_conductor->contextComboBox()-> addItem(tr("Sans nom"));
|
||||
}
|
||||
// If the text isn't yet to the autonum of the project, add this new item to the combo box.
|
||||
else if ( !m_project -> conductorAutoNum().keys().contains( m_saw_conductor->contextComboBox()->currentText()))
|
||||
else if ( !m_project -> conductorAutoNum().contains( m_saw_conductor->contextComboBox()->currentText()))
|
||||
{
|
||||
project()->addConductorAutoNum(m_saw_conductor->contextComboBox()->currentText(), m_saw_conductor->toNumContext());
|
||||
project()->setCurrentConductorAutoNum(m_saw_conductor->contextComboBox()->currentText());
|
||||
@@ -489,7 +489,7 @@ void ProjectAutoNumConfigPage::saveContextFolio()
|
||||
m_saw_folio->contextComboBox() -> addItem(tr("Sans nom"));
|
||||
}
|
||||
// If the text isn't yet to the autonum of the project, add this new item to the combo box.
|
||||
else if ( !m_project -> folioAutoNum().keys().contains( m_saw_folio->contextComboBox()->currentText())) {
|
||||
else if ( !m_project -> folioAutoNum().contains( m_saw_folio->contextComboBox()->currentText())) {
|
||||
project()->addFolioAutoNum(m_saw_folio->contextComboBox()->currentText(), m_saw_folio->toNumContext());
|
||||
m_saw_folio->contextComboBox() -> addItem(m_saw_folio->contextComboBox()->currentText());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user