summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Rolf Eike Beer <eike@sf-mail.de>2019-04-03 23:05:44 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-04-12 12:59:17 +0300
commit36644dc9f7540886801bda6131dff36241d9e879 (patch)
treeacd090b1cd50c3847fc817c3f675dc9965190e3c /core
parent1f4777a2877e1df3215e03e48204333cb160a2c6 (diff)
downloadsubsurface-36644dc9f7540886801bda6131dff36241d9e879.tar.gz
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>
Diffstat (limited to 'core')
-rw-r--r--core/qthelper.cpp11
-rw-r--r--core/qthelper.h2
2 files changed, 8 insertions, 5 deletions
diff --git a/core/qthelper.cpp b/core/qthelper.cpp
index 35965208c..9483d9ab5 100644
--- a/core/qthelper.cpp
+++ b/core/qthelper.cpp
@@ -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()
diff --git a/core/qthelper.h b/core/qthelper.h
index cbe2b77f0..3b7ff2c59 100644
--- a/core/qthelper.h
+++ b/core/qthelper.h
@@ -80,7 +80,7 @@ QString get_short_dive_date_string(timestamp_t when);
QString get_trip_date_string(timestamp_t when, int nr, bool getday);
QString uiLanguage(QLocale *callerLoc);
QLocale getLocale();
-void selectedDivesGasUsed(QVector<QPair<QString, int> > &gasUsed);
+QVector<QPair<QString, int>> selectedDivesGasUsed();
QString getUserAgent();
QString printGPSCoords(const location_t *loc);