Commit 7d47b470 authored by Anselmo L. S. Melo's avatar Anselmo L. S. Melo
Browse files

Review iterations over QStrings

There are many ways of iterating over lists in C++/Qt.
In the specific case of QStrings, it is known [1] that using
foreach with const references avoids the creation of new
QString objects in each iteration, reducing the time consumed
by the loops.

[1] https://blog.qt.io/blog/2009/01/23/iterating-efficiently/



Signed-off-by: default avatarAnselmo L. S. Melo <anselmo.melo@intel.com>
parent a4e6fd28
......@@ -407,7 +407,7 @@ void RadioConfigTest::_fullCalibrationWorker(MAV_AUTOPILOT firmwareType)
QStringList switchList;
switchList << "RC_MAP_MODE_SW" << "RC_MAP_LOITER_SW" << "RC_MAP_RETURN_SW" << "RC_MAP_POSCTL_SW" << "RC_MAP_ACRO_SW";
foreach (QString switchParam, switchList) {
foreach (const QString &switchParam, switchList) {
Q_ASSERT(_autopilot->getParameterFact(FactSystem::defaultComponentId, switchParam)->rawValue().toInt() != channel + 1);
}
}
......
......@@ -183,7 +183,7 @@ void LinechartPlot::setActive(bool active)
void LinechartPlot::removeTimedOutCurves()
{
foreach(QString key, lastUpdate.keys())
foreach(const QString &key, lastUpdate.keys())
{
quint64 time = lastUpdate.value(key);
if (QGC::groundTimeMilliseconds() - time > 10000)
......@@ -499,7 +499,7 @@ bool LinechartPlot::isVisible(QString id)
bool LinechartPlot::anyCurveVisible()
{
bool visible = false;
foreach (QString key, curves.keys())
foreach (const QString &key, curves.keys())
{
if (curves.value(key)->isVisible())
{
......
......@@ -673,7 +673,7 @@ void LinechartWidget::removeCurve(QString curve)
void LinechartWidget::recolor()
{
activePlot->styleChanged(qgcApp()->styleIsDark());
foreach (QString key, colorIcons.keys())
foreach (const QString &key, colorIcons.keys())
{
QWidget* colorIcon = colorIcons.value(key, 0);
if (colorIcon && !colorIcon->styleSheet().isEmpty())
......@@ -713,7 +713,7 @@ void LinechartWidget::filterCurves(const QString &filter)
{
/* Hide Elements which do not match the filter pattern */
QStringMatcher stringMatcher(filter, Qt::CaseInsensitive);
foreach (QString key, colorIcons.keys())
foreach (const QString &key, colorIcons.keys())
{
if (stringMatcher.indexIn(key) < 0)
{
......@@ -728,7 +728,7 @@ void LinechartWidget::filterCurves(const QString &filter)
else
{
/* Show all Elements */
foreach (QString key, colorIcons.keys())
foreach (const QString &key, colorIcons.keys())
{
filterCurve(key, true);
}
......@@ -796,7 +796,7 @@ QString LinechartWidget::getCurveName(const QString& key, bool shortEnabled)
void LinechartWidget::setShortNames(bool enable)
{
foreach (QString key, curveNames.keys())
foreach (const QString &key, curveNames.keys())
{
curveNameLabels.value(key)->setText(getCurveName(key, enable));
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment