Refactoring.

Fix places that could use a reserve() call.
This commit is contained in:
Roman Telezhynskyi 2024-04-17 13:02:25 +03:00
parent afd948b330
commit f1081a2aad
5 changed files with 61 additions and 43 deletions

View File

@ -414,6 +414,7 @@ auto VAbstractPattern::GetActivDrawElement(QDomElement &element) const -> bool
auto VAbstractPattern::getLocalHistory(const QString &draw) const -> QVector<VToolRecord> auto VAbstractPattern::getLocalHistory(const QString &draw) const -> QVector<VToolRecord>
{ {
QVector<VToolRecord> historyPP; QVector<VToolRecord> historyPP;
historyPP.reserve(history.size());
for (qint32 i = 0; i < history.size(); ++i) for (qint32 i = 0; i < history.size(); ++i)
{ {
const VToolRecord &tool = history.at(i); const VToolRecord &tool = history.at(i);
@ -733,8 +734,9 @@ auto VAbstractPattern::ParsePieceNodes(const QDomElement &domElement) -> VPieceP
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VAbstractPattern::ParsePieceCSARecords(const QDomElement &domElement) -> QVector<CustomSARecord> auto VAbstractPattern::ParsePieceCSARecords(const QDomElement &domElement) -> QVector<CustomSARecord>
{ {
QVector<CustomSARecord> records;
const QDomNodeList nodeList = domElement.childNodes(); const QDomNodeList nodeList = domElement.childNodes();
QVector<CustomSARecord> records;
records.reserve(nodeList.size());
for (qint32 i = 0; i < nodeList.size(); ++i) for (qint32 i = 0; i < nodeList.size(); ++i)
{ {
const QDomElement element = nodeList.at(i).toElement(); const QDomElement element = nodeList.at(i).toElement();
@ -756,8 +758,9 @@ auto VAbstractPattern::ParsePieceCSARecords(const QDomElement &domElement) -> QV
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VAbstractPattern::ParsePieceInternalPaths(const QDomElement &domElement) -> QVector<quint32> auto VAbstractPattern::ParsePieceInternalPaths(const QDomElement &domElement) -> QVector<quint32>
{ {
QVector<quint32> records;
const QDomNodeList nodeList = domElement.childNodes(); const QDomNodeList nodeList = domElement.childNodes();
QVector<quint32> records;
records.reserve(nodeList.size());
for (qint32 i = 0; i < nodeList.size(); ++i) for (qint32 i = 0; i < nodeList.size(); ++i)
{ {
const QDomElement element = nodeList.at(i).toElement(); const QDomElement element = nodeList.at(i).toElement();
@ -1759,6 +1762,7 @@ auto VAbstractPattern::ListIncrements() const -> QStringList
auto GetExpressions = [&increments, this](const QString &type) auto GetExpressions = [&increments, this](const QString &type)
{ {
const QDomNodeList list = elementsByTagName(type); const QDomNodeList list = elementsByTagName(type);
increments.reserve(list.size());
for (int i = 0; i < list.size(); ++i) for (int i = 0; i < list.size(); ++i)
{ {
const QString name = GetParametrEmptyString(list.at(i).toElement(), AttrName); const QString name = GetParametrEmptyString(list.at(i).toElement(), AttrName);
@ -2636,6 +2640,7 @@ auto VAbstractPattern::GetGroups(const QString &patternPieceName) -> QMap<quint3
const QDomNodeList nodeList = group.childNodes(); const QDomNodeList nodeList = group.childNodes();
const qint32 num = nodeList.size(); const qint32 num = nodeList.size();
items.reserve(num);
for (qint32 i = 0; i < num; ++i) for (qint32 i = 0; i < num; ++i)
{ {
const QDomElement element = nodeList.at(i).toElement(); const QDomElement element = nodeList.at(i).toElement();

View File

@ -2238,6 +2238,7 @@ void VPatternConverter::TagUnionDetailsToV0_4_0()
QDomElement tagChildrenNodes = createElement(*strChildren); QDomElement tagChildrenNodes = createElement(*strChildren);
const QDomNodeList childList = toolDOM.childNodes(); const QDomNodeList childList = toolDOM.childNodes();
nodes.reserve(childList.size());
for (qint32 i = 0; i < childList.size(); ++i) for (qint32 i = 0; i < childList.size(); ++i)
{ {
const QDomElement element = childList.at(i).toElement(); const QDomElement element = childList.at(i).toElement();

View File

@ -33,16 +33,18 @@
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VAbstartMeasurementDimension::VAbstartMeasurementDimension(Unit units) VAbstartMeasurementDimension::VAbstartMeasurementDimension(Unit units)
: m_units(units) : m_units(units)
{} {
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VAbstartMeasurementDimension::VAbstartMeasurementDimension(Unit units, qreal min, qreal max, qreal step) VAbstartMeasurementDimension::VAbstartMeasurementDimension(Unit units, qreal min, qreal max, qreal step)
: m_units(units), : m_units(units),
m_minValue(min), m_minValue(min),
m_maxValue(max), m_maxValue(max),
m_step(step) m_step(step)
{} {
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VAbstartMeasurementDimension::IsValid() -> bool auto VAbstartMeasurementDimension::IsValid() -> bool
@ -60,7 +62,7 @@ auto VAbstartMeasurementDimension::RangeMin() const -> int
const int rangeMinMm = 200; const int rangeMinMm = 200;
const int rangeMinInch = 8; const int rangeMinInch = 8;
switch(Units()) switch (Units())
{ {
case Unit::Cm: case Unit::Cm:
return rangeMinCm; return rangeMinCm;
@ -85,7 +87,7 @@ auto VAbstartMeasurementDimension::RangeMax() const -> int
const int rangeMaxMm = 2720; const int rangeMaxMm = 2720;
const int rangeMaxInch = 107; const int rangeMaxInch = 107;
switch(Units()) switch (Units())
{ {
case Unit::Cm: case Unit::Cm:
return rangeMaxCm; return rangeMaxCm;
@ -135,8 +137,7 @@ auto VAbstartMeasurementDimension::ValidSteps() const -> QVector<qreal>
} }
candidate = 1 + s * i; candidate = 1 + s * i;
++i; ++i;
} } while (candidate < stepBarrier);
while(candidate < stepBarrier);
} }
return steps; return steps;
@ -159,12 +160,11 @@ auto VAbstartMeasurementDimension::ValidBasesList() const -> QStringList
list.append(QString::number(base)); list.append(QString::number(base));
} }
return list; return list;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VAbstartMeasurementDimension::ValidBases(qreal min, qreal max, qreal step, auto VAbstartMeasurementDimension::ValidBases(qreal min, qreal max, qreal step, const QSet<qreal> &exclude)
const QSet<qreal> &exclude) -> QVector<qreal> -> QVector<qreal>
{ {
QVector<qreal> validBases; QVector<qreal> validBases;
@ -190,8 +190,7 @@ auto VAbstartMeasurementDimension::ValidBases(qreal min, qreal max, qreal step,
} }
value = min + step * i; value = min + step * i;
++i; ++i;
} } while (value < max + step);
while(value < max + step);
if (validBases.isEmpty()) if (validBases.isEmpty())
{ {
@ -202,8 +201,7 @@ auto VAbstartMeasurementDimension::ValidBases(qreal min, qreal max, qreal step,
validBases.append(value); validBases.append(value);
value = min + step * i; value = min + step * i;
++i; ++i;
} } while (value < max + step);
while(value < max + step);
} }
return validBases; return validBases;
@ -265,7 +263,7 @@ auto VAbstartMeasurementDimension::IsUnitsValid() const -> bool
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VAbstartMeasurementDimension::DimensionName(MeasurementDimension type) -> QString auto VAbstartMeasurementDimension::DimensionName(MeasurementDimension type) -> QString
{ {
switch(type) switch (type)
{ {
case MeasurementDimension::X: case MeasurementDimension::X:
return QCoreApplication::translate("VAbstartMeasurementDimension", "Height", "dimension"); return QCoreApplication::translate("VAbstartMeasurementDimension", "Height", "dimension");
@ -288,7 +286,7 @@ auto VAbstartMeasurementDimension::DimensionToolTip(const MeasurementDimension_p
return {}; return {};
} }
switch(dimension->Type()) switch (dimension->Type())
{ {
case MeasurementDimension::Y: case MeasurementDimension::Y:
if (dimension->CustomName().isEmpty() && dimension->IsBodyMeasurement()) if (dimension->CustomName().isEmpty() && dimension->IsBodyMeasurement())
@ -326,51 +324,59 @@ auto VAbstartMeasurementDimension::DimensionToolTip(const MeasurementDimension_p
// VXMeasurementDimension // VXMeasurementDimension
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VXMeasurementDimension::VXMeasurementDimension(Unit units) VXMeasurementDimension::VXMeasurementDimension(Unit units)
: VAbstartMeasurementDimension(units) : VAbstartMeasurementDimension(units)
{} {
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VXMeasurementDimension::VXMeasurementDimension(Unit units, qreal min, qreal max, qreal step) VXMeasurementDimension::VXMeasurementDimension(Unit units, qreal min, qreal max, qreal step)
: VAbstartMeasurementDimension(units, min, max, step) : VAbstartMeasurementDimension(units, min, max, step)
{} {
}
// VYMeasurementDimension // VYMeasurementDimension
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VYMeasurementDimension::VYMeasurementDimension(Unit units) VYMeasurementDimension::VYMeasurementDimension(Unit units)
: VAbstartMeasurementDimension(units) : VAbstartMeasurementDimension(units)
{} {
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VYMeasurementDimension::VYMeasurementDimension(Unit units, qreal min, qreal max, qreal step) VYMeasurementDimension::VYMeasurementDimension(Unit units, qreal min, qreal max, qreal step)
: VAbstartMeasurementDimension(units, min, max, step) : VAbstartMeasurementDimension(units, min, max, step)
{} {
}
// VWMeasurementDimension // VWMeasurementDimension
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VWMeasurementDimension::VWMeasurementDimension(Unit units) VWMeasurementDimension::VWMeasurementDimension(Unit units)
: VAbstartMeasurementDimension(units) : VAbstartMeasurementDimension(units)
{} {
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VWMeasurementDimension::VWMeasurementDimension(Unit units, qreal min, qreal max, qreal step) VWMeasurementDimension::VWMeasurementDimension(Unit units, qreal min, qreal max, qreal step)
: VAbstartMeasurementDimension(units, min, max, step) : VAbstartMeasurementDimension(units, min, max, step)
{} {
}
// VZMeasurementDimension // VZMeasurementDimension
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VZMeasurementDimension::VZMeasurementDimension(Unit units) VZMeasurementDimension::VZMeasurementDimension(Unit units)
: VAbstartMeasurementDimension(units) : VAbstartMeasurementDimension(units)
{} {
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VZMeasurementDimension::VZMeasurementDimension(Unit units, qreal min, qreal max, qreal step) VZMeasurementDimension::VZMeasurementDimension(Unit units, qreal min, qreal max, qreal step)
: VAbstartMeasurementDimension(units, min, max, step) : VAbstartMeasurementDimension(units, min, max, step)
{} {
}
// VDimensionRestriction // VDimensionRestriction
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VDimensionRestriction::VDimensionRestriction(qreal min, qreal max, const QString &exclude) : VDimensionRestriction::VDimensionRestriction(qreal min, qreal max, const QString &exclude)
m_min(min), : m_min(min),
m_max(max) m_max(max)
{ {
SetExcludeString(exclude); SetExcludeString(exclude);
@ -399,6 +405,7 @@ auto VDimensionRestriction::GetExcludeString() const -> QString
{ {
QList<qreal> const list = m_exclude.values(); QList<qreal> const list = m_exclude.values();
QStringList excludeList; QStringList excludeList;
excludeList.reserve(list.size());
for (const auto &value : list) for (const auto &value : list)
{ {

View File

@ -680,6 +680,7 @@ auto VLayoutGenerator::MoveDetails(qreal length, const QVector<VLayoutPiece> &de
} }
QList<VLayoutPiece> newDetails; QList<VLayoutPiece> newDetails;
newDetails.reserve(details.size());
for (auto d : details) for (auto d : details)
{ {
IsPortrait() ? d.Translate(0, length) : d.Translate(length, 0); IsPortrait() ? d.Translate(0, length) : d.Translate(length, 0);

View File

@ -213,6 +213,7 @@ void VObjEngine::drawPath(const QPainterPath &path)
if (skipFace == false) if (skipFace == false)
{ {
QPolygonF face; QPolygonF face;
face.reserve(num_verts);
for (int ind = 0; ind < num_verts; ind++) for (int ind = 0; ind < num_verts; ind++)
{ {
face << QPointF(pf[ind]); face << QPointF(pf[ind]);
@ -334,13 +335,16 @@ auto VObjEngine::MakePointsUnique(const QPolygonF &polygon) const -> QPolygonF
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VObjEngine::Square(const QPolygonF &poly) const -> qint64 auto VObjEngine::Square(const QPolygonF &poly) const -> qint64
{ {
QVector<qreal> x;
QVector<qreal> y;
vsizetype const n = poly.count(); vsizetype const n = poly.count();
qreal s, res = 0; qreal s, res = 0;
qint64 sq = 0; qint64 sq = 0;
QVector<qreal> x;
QVector<qreal> y;
x.reserve(n);
y.reserve(n);
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
{ {
x.append(poly.at(i).x()); x.append(poly.at(i).x());