refs #937 Resolved clazy warnings: unnecessary memory allocation.

This commit is contained in:
Mathew Sutcliffe
2017-04-17 00:03:33 +01:00
parent fce1513dae
commit b7f69c6887
26 changed files with 52 additions and 51 deletions

View File

@@ -219,7 +219,7 @@ namespace BlackMisc
QString CAircraftIcaoCode::getAircraftType() const
{
if (this->m_combinedType.length() < 1) { return ""; }
QString c(this->m_combinedType.left(1));
QString c(this->m_combinedType.at(0));
if (c == "-") { return ""; }
return c;
}
@@ -587,10 +587,10 @@ namespace BlackMisc
}
// turn E to P engine
if (combinedCode.endsWith("E")) { return QStringList({ combinedCode.left(2) + "P"}); }
if (combinedCode.endsWith("E")) { return QStringList({ combinedCode.leftRef(2) + "P"}); }
// turn T to H plane (tilt wing to helicopter
if (combinedCode.startsWith("T")) { return QStringList({ "H" + combinedCode.right(2)}); }
if (combinedCode.startsWith("T")) { return QStringList({ "H" + combinedCode.rightRef(2)}); }
// based on engine count
QStringList codes;
@@ -600,7 +600,7 @@ namespace BlackMisc
for (int c = 2; c < 5; c++)
{
if (c == engineCount) { continue; }
const QString code(combinedCode.left(1) + QString::number(c) + combinedCode.right(1));
const QString code(combinedCode.at(0) + QString::number(c) + combinedCode.at(2));
codes.push_back(code);
}
}
@@ -667,7 +667,7 @@ namespace BlackMisc
}
else
{
c.append(engine.left(1));
c.append(engine.at(0));
}
Q_ASSERT_X(c.length() == 3, Q_FUNC_INFO, "Wrong combined length");
return c;

View File

@@ -408,7 +408,7 @@ namespace BlackMisc
if (pinsOnly)
{
auto pins = fromJson(json.value("pins").toArray());
for (const auto &key : m_timestamps.keys())
for (const auto &key : m_timestamps.keys()) // clazy:exclude=container-anti-pattern,range-loop
{
if (! pins.contains(key)) { m_timestamps.remove(key); }
}

View File

@@ -127,12 +127,12 @@ namespace BlackMisc
{
if (part.startsWith("host="))
{
host = part.mid(part.lastIndexOf("=") + 1).trimmed();
host = part.midRef(part.lastIndexOf("=") + 1).trimmed().toString();
}
else if (part.startsWith("port="))
{
bool ok;
port = part.mid(part.lastIndexOf("=") + 1).trimmed().toInt(&ok);
port = part.midRef(part.lastIndexOf("=") + 1).trimmed().toInt(&ok);
if (! ok) { port = -1; }
}
}
@@ -265,7 +265,7 @@ namespace BlackMisc
void CDBusServer::removeAllObjects()
{
if (m_objects.isEmpty()) { return; }
for (const QString &path : m_objects.keys())
for (const QString &path : makeKeysRange(as_const(m_objects)))
{
switch (m_serverMode)
{

View File

@@ -414,7 +414,7 @@ namespace BlackMisc
QJsonObject getIncrementalObject(const QJsonObject &previousObject, const QJsonObject &currentObject)
{
QJsonObject incrementalObject = currentObject;
for (const auto &key : previousObject.keys())
for (const auto &key : previousObject.keys()) // clazy:exclude=range-loop
{
if (previousObject.value(key).isObject())
{
@@ -434,7 +434,7 @@ namespace BlackMisc
QJsonObject applyIncrementalObject(const QJsonObject &previousObject, const QJsonObject &incrementalObject)
{
QJsonObject currentObject = previousObject;
for (const auto &key : incrementalObject.keys())
for (const auto &key : incrementalObject.keys()) // clazy:exclude=range-loop
{
// If it is not an object, just insert the value
if (!incrementalObject.value(key).isObject())

View File

@@ -310,7 +310,7 @@ namespace BlackMisc
{
Q_UNUSED(i18n);
QString strategy;
QString categories = QStringList(m_strings.toList()).join("|");
QString categories = QStringList(m_strings.toList()).join("|"); // clazy:exclude=container-anti-pattern
switch (m_strategy)
{
case Everything: strategy = "none"; break;

View File

@@ -102,7 +102,7 @@ namespace BlackMisc
{
int pos = match.capturedStart(0);
QString icao = match.captured(0).trimmed().right(4);
rn = rn.left(pos).trimmed();
rn = rn.leftRef(pos).trimmed().toString();
this->setHomeBase(CAirportIcaoCode(icao));
}
}

View File

@@ -66,10 +66,10 @@ namespace BlackMisc
if (ts.contains(":") && (ts.length() == 8 || ts.length() == 5))
{
const int hour = ts.mid(0, 2).toInt();
const int minute = ts.mid(3, 2).toInt();
const int hour = ts.midRef(0, 2).toInt();
const int minute = ts.midRef(3, 2).toInt();
int second = 0;
if (ts.length() == 8) second = ts.mid(6, 2).toInt();
if (ts.length() == 8) second = ts.midRef(6, 2).toInt();
(*this) = CTime(hour, minute, second);
// fix sign if required

View File

@@ -138,7 +138,7 @@ namespace BlackMisc
}
else
{
f = this->m_indexString.left(p).toInt(&ok);
f = this->m_indexString.leftRef(p).toInt(&ok);
}
Q_ASSERT_X(ok && f >= 0, Q_FUNC_INFO, "Invalid index");
return f;

View File

@@ -53,7 +53,7 @@ namespace BlackMisc
{
if (this->isEmpty()) return QString("{wildcard: %1}").arg(this->m_wildcard ? "true" : "false");
QString s;
foreach (CPropertyIndex index, this->m_values.keys())
for (const CPropertyIndex &index : makeKeysRange(this->m_values))
{
CVariant v = this->m_values.value(index);

View File

@@ -75,7 +75,7 @@ namespace BlackMisc
obj.insert("name", this->getName());
obj.insert("modelstring", QJsonValue(this->m_modelString));
obj.insert("description", QJsonValue(this->m_description));
obj.insert("mode", QJsonValue(getModelModeAsString().left(1).toUpper()));
obj.insert("mode", QJsonValue(getModelModeAsString().left(1).toUpper())); // clazy:exclude=qstring-left
// sims
const CSimulatorInfo sim(getSimulator());

View File

@@ -219,7 +219,7 @@ namespace BlackMisc
QString fltSection("[FLTSIM.0]");
int fltsimCounter = 0;
FileSection currentSection = Unknown;
bool isRotorcraftPath = fileName.toLower().contains("rotorcraft");
bool isRotorcraftPath = fileName.contains("rotorcraft", Qt::CaseInsensitive);
while (!in.atEnd())
{
@@ -391,7 +391,7 @@ namespace BlackMisc
if (index < 0) { return ""; }
if (line.length() < index + 1) { return ""; }
QString content(line.mid(index + 1).trimmed());
QString content(line.midRef(index + 1).trimmed().toString());
// fix "" strings, some are malformed and just contain " at beginning, not at the end
if (content.endsWith('"')) { content.remove(content.size() - 1 , 1); }

View File

@@ -47,9 +47,9 @@ namespace BlackMisc
QString s(yyyyMMddhhmmsszzz);
s.remove(':').remove(' ').remove('-').remove('.'); // plain vanilla string
int year(s.left(4).toInt());
int month(s.mid(4, 2).toInt());
int day(s.mid(6, 2).toInt());
int year(s.leftRef(4).toInt());
int month(s.midRef(4, 2).toInt());
int day(s.midRef(6, 2).toInt());
QDate date;
date.setDate(year, month, day);
QDateTime dt;
@@ -62,10 +62,10 @@ namespace BlackMisc
}
QTime t;
int hour(s.mid(8, 2).toInt());
int minute(s.mid(10, 2).toInt());
int second(s.length() < 14 ? 0 : s.mid(12, 2).toInt());
int ms(s.length() < 17 ? 0 : s.right(3).toInt());
int hour(s.midRef(8, 2).toInt());
int minute(s.midRef(10, 2).toInt());
int second(s.length() < 14 ? 0 : s.midRef(12, 2).toInt());
int ms(s.length() < 17 ? 0 : s.rightRef(3).toInt());
t.setHMS(hour, minute, second, ms);
dt.setTime(t);

View File

@@ -458,7 +458,7 @@ namespace BlackMisc
CVariantMap temp;
if (keysOnly)
{
for (const auto &key : json.object().keys()) { temp.insert(key, {}); }
for (const auto &key : json.object().keys()) { temp.insert(key, {}); } // clazy:exclude=range-loop
}
else
{

View File

@@ -115,7 +115,7 @@ namespace BlackMisc
};
QString weatherPhenomenaAsString;
for (const auto &wp : weatherPhenomenaHash.keys())
for (const auto &wp : makeKeysRange(weatherPhenomenaHash))
{
if (m_weatherPhenomena & wp)
{