uic: replace an inefficient QList with QVector
Buddy is larger than a void*, so holding it in QLists is needlessly inefficient. Worse, the code could come to depend on the fragile property of (inefficient) QLists that references to elements therein never are invalidated. Fix by marking it movable, and holding it in a QVector instead. Since QVector requires a default ctor, drop the pointless existing ctor and use aggregate initialization instead. Use QVector's rvalue append. Change-Id: I696ca4f03dbe362a5438be209debbcd966fe8130 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
This commit is contained in:
parent
ba08832a4e
commit
612e082fe2
@ -1277,7 +1277,8 @@ void WriteInitialization::writeProperties(const QString &varName,
|
||||
break;
|
||||
case DomProperty::Cstring:
|
||||
if (propertyName == QLatin1String("buddy") && m_uic->customWidgetsInfo()->extends(className, QLatin1String("QLabel"))) {
|
||||
m_buddies.append(Buddy(varName, p->elementCstring()));
|
||||
Buddy buddy = { varName, p->elementCstring() };
|
||||
m_buddies.append(std::move(buddy));
|
||||
} else {
|
||||
if (stdset)
|
||||
propertyValue = fixString(p->elementCstring(), m_dindent);
|
||||
|
@ -251,16 +251,15 @@ private:
|
||||
|
||||
struct Buddy
|
||||
{
|
||||
Buddy(const QString &oN, const QString &b)
|
||||
: objName(oN), buddy(b) {}
|
||||
QString objName;
|
||||
QString buddy;
|
||||
};
|
||||
friend class QTypeInfo<Buddy>;
|
||||
|
||||
QStack<DomWidget*> m_widgetChain;
|
||||
QStack<DomLayout*> m_layoutChain;
|
||||
QStack<DomActionGroup*> m_actionGroupChain;
|
||||
QList<Buddy> m_buddies;
|
||||
QVector<Buddy> m_buddies;
|
||||
|
||||
QSet<QString> m_buttonGroups;
|
||||
QHash<QString, DomWidget*> m_registeredWidgets;
|
||||
@ -323,6 +322,8 @@ private:
|
||||
|
||||
} // namespace CPP
|
||||
|
||||
Q_DECLARE_TYPEINFO(CPP::WriteInitialization::Buddy, Q_MOVABLE_TYPE);
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // CPPWRITEINITIALIZATION_H
|
||||
|
Loading…
Reference in New Issue
Block a user