T73 Pass units by value.

Class types which are trivial to copy should be passed by value.
This commit is contained in:
Mathew Sutcliffe
2017-04-21 20:02:09 +01:00
parent c8d78ada65
commit 07ec7e6bc1
3 changed files with 17 additions and 20 deletions

View File

@@ -341,10 +341,9 @@ namespace BlackMisc
template <class U> static U unitFromSymbol(const QString &symbol, bool strict = true)
{
if (symbol.isEmpty()) return U::defaultUnit();
const QList<U> &units = U::allUnits();
for (int i = 0; i < units.size(); ++i)
for (const auto unit : U::allUnits())
{
if (units.at(i).getSymbol() == symbol) return units.at(i);
if (unit.getSymbol() == symbol) { return unit; }
}
if (strict) qFatal("Illegal unit name");
return U::defaultUnit();
@@ -358,11 +357,9 @@ namespace BlackMisc
template <class U> static bool isValidUnitSymbol(const QString &symbol, Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive)
{
if (symbol.isEmpty()) return false;
const QList<U> &units = U::allUnits();
for (int i = 0; i < units.size(); ++i)
for (const auto unit : U::allUnits())
{
if (caseSensitivity == Qt::CaseSensitive && units.at(i).getSymbol() == symbol) return true;
if (units.at(i).getSymbol().compare(symbol, Qt::CaseInsensitive) == 0) return 0;
if (QString::compare(unit.getSymbol(), symbol, caseSensitivity) == 0) { return true; }
}
return false;
}