mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-07-31 00:24: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:
@@ -130,7 +130,7 @@ QList<QStandardItem *> DynamicElementTextModel::itemsForText(
|
||||
{
|
||||
QList <QStandardItem *> qsi_list;
|
||||
|
||||
if(m_texts_list.keys().contains(deti))
|
||||
if(m_texts_list.contains(deti))
|
||||
return qsi_list;
|
||||
|
||||
QStandardItem *qsi = new QStandardItem(deti->toPlainText());
|
||||
@@ -718,7 +718,7 @@ QUndoCommand *DynamicElementTextModel::undoForEditedGroup(
|
||||
*/
|
||||
void DynamicElementTextModel::addGroup(ElementTextItemGroup *group)
|
||||
{
|
||||
if(m_groups_list.keys().contains(group))
|
||||
if(m_groups_list.contains(group))
|
||||
return;
|
||||
|
||||
//Group
|
||||
@@ -869,7 +869,7 @@ void DynamicElementTextModel::addGroup(ElementTextItemGroup *group)
|
||||
*/
|
||||
void DynamicElementTextModel::removeGroup(ElementTextItemGroup *group)
|
||||
{
|
||||
if(m_groups_list.keys().contains(group))
|
||||
if(m_groups_list.contains(group))
|
||||
{
|
||||
QModelIndex group_index = m_groups_list.value(group)->index();
|
||||
this->removeRow(group_index.row(), group_index.parent());
|
||||
@@ -896,7 +896,7 @@ void DynamicElementTextModel::removeTextFromGroup(DynamicElementTextItem *deti,
|
||||
{
|
||||
Q_UNUSED(group)
|
||||
|
||||
if(m_texts_list.keys().contains(deti))
|
||||
if(m_texts_list.contains(deti))
|
||||
{
|
||||
QStandardItem *text_item = m_texts_list.value(deti);
|
||||
QModelIndex text_index = indexFromItem(text_item);
|
||||
@@ -961,7 +961,7 @@ ElementTextItemGroup *DynamicElementTextModel::groupFromItem(
|
||||
QModelIndex DynamicElementTextModel::indexFromGroup(
|
||||
ElementTextItemGroup *group) const
|
||||
{
|
||||
if(m_groups_list.keys().contains(group))
|
||||
if(m_groups_list.contains(group))
|
||||
return m_groups_list.value(group)->index();
|
||||
else
|
||||
return QModelIndex();
|
||||
@@ -1371,7 +1371,7 @@ void DynamicElementTextModel::setConnection(DynamicElementTextItem *deti, bool s
|
||||
{
|
||||
if(set)
|
||||
{
|
||||
if(m_hash_text_connect.keys().contains(deti))
|
||||
if(m_hash_text_connect.contains(deti))
|
||||
return;
|
||||
|
||||
QList<QMetaObject::Connection> connection_list;
|
||||
@@ -1390,7 +1390,7 @@ void DynamicElementTextModel::setConnection(DynamicElementTextItem *deti, bool s
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!m_hash_text_connect.keys().contains(deti))
|
||||
if(!m_hash_text_connect.contains(deti))
|
||||
return;
|
||||
|
||||
for (const QMetaObject::Connection& con : m_hash_text_connect.value(deti))
|
||||
@@ -1412,7 +1412,7 @@ void DynamicElementTextModel::setConnection(ElementTextItemGroup *group, bool se
|
||||
{
|
||||
if(set)
|
||||
{
|
||||
if(m_hash_group_connect.keys().contains(group))
|
||||
if(m_hash_group_connect.contains(group))
|
||||
return;
|
||||
|
||||
QList<QMetaObject::Connection> connection_list;
|
||||
@@ -1429,7 +1429,7 @@ void DynamicElementTextModel::setConnection(ElementTextItemGroup *group, bool se
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!m_hash_group_connect.keys().contains(group))
|
||||
if(!m_hash_group_connect.contains(group))
|
||||
return;
|
||||
|
||||
for (const QMetaObject::Connection& con : m_hash_group_connect.value(group))
|
||||
|
||||
Reference in New Issue
Block a user