mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
optimize selectedDivesGasUsed()
-return the result instead of storing in a parameter, we now know that the list contains only those results that are generated in the function -allocate the result with the correct length right from the start -do not iterate over keys of a map and then do a map lookup to get the value but use an iterator that gives us both right from the start -remove one call alltogether as the results were not used there Signed-off-by: Rolf Eike Beer <eike@sf-mail.de>
This commit is contained in:
parent
1f4777a287
commit
36644dc9f7
4 changed files with 9 additions and 22 deletions
|
|
@ -375,7 +375,7 @@ static bool lessThan(const QPair<QString, int> &a, const QPair<QString, int> &b)
|
|||
return a.second < b.second;
|
||||
}
|
||||
|
||||
void selectedDivesGasUsed(QVector<QPair<QString, int> > &gasUsedOrdered)
|
||||
QVector<QPair<QString, int>> selectedDivesGasUsed()
|
||||
{
|
||||
int i, j;
|
||||
struct dive *d;
|
||||
|
|
@ -391,10 +391,13 @@ void selectedDivesGasUsed(QVector<QPair<QString, int> > &gasUsedOrdered)
|
|||
gasUsed[gasName] += diveGases[j].mliter;
|
||||
}
|
||||
}
|
||||
Q_FOREACH(const QString& gas, gasUsed.keys()) {
|
||||
gasUsedOrdered.append(qMakePair(gas, gasUsed[gas]));
|
||||
}
|
||||
QVector<QPair<QString, int>> gasUsedOrdered;
|
||||
gasUsedOrdered.reserve(gasUsed.size());
|
||||
for (auto it = gasUsed.cbegin(); it != gasUsed.cend(); ++it)
|
||||
gasUsedOrdered.append(qMakePair(it.key(), it.value()));
|
||||
std::sort(gasUsedOrdered.begin(), gasUsedOrdered.end(), lessThan);
|
||||
|
||||
return gasUsedOrdered;
|
||||
}
|
||||
|
||||
QString getUserAgent()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue