summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2017-12-20 00:01:42 +0100
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2017-12-21 00:04:30 +0100
commit28ae35e7df7c32ef6070474ad0e55c5a473f701d (patch)
tree804b865381da574f72aa362a629d30c800148f31
parent22dc7b84f091b392537ab51539c4277ad54416de (diff)
downloadsubsurface-28ae35e7df7c32ef6070474ad0e55c5a473f701d.tar.gz
Make QMap<> access in deleteGpsFix() more idiomatic
To access a QMap<> entry, the value() function is used with a sentinel as default value. If the sentinel is returned, the code assumes that the searched for entry doesn't exist. Make this code more idiomatic by using an iterator and testing for end(). This fixes a compiler warning, because only one of the elements of the sentinel was initialized, but the remaining elements were copied. Harmless, because the code would exit early if it found the sentinel. Still not nice. While redoing this function, the entry-not-found message was improved (adding of function name, space between massage and timestamp) and elevated from debug to warning level. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--core/gpslocation.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/core/gpslocation.cpp b/core/gpslocation.cpp
index 2d65ae211..9db829b02 100644
--- a/core/gpslocation.cpp
+++ b/core/gpslocation.cpp
@@ -436,13 +436,12 @@ void GpsLocation::deleteFixFromStorage(gpsTracker &gt)
void GpsLocation::deleteGpsFix(qint64 when)
{
- struct gpsTracker defaultTracker;
- defaultTracker.when = 0;
- struct gpsTracker deletedTracker = m_trackers.value(when, defaultTracker);
- if (deletedTracker.when != when) {
- qDebug() << "can't find tracker for timestamp" << when;
+ auto it = m_trackers.find(when);
+ if (it == m_trackers.end()) {
+ qWarning() << "GpsLocation::deleteGpsFix(): can't find tracker for timestamp " << when;
return;
}
+ struct gpsTracker deletedTracker = *it;
deleteFixFromStorage(deletedTracker);
m_deletedTrackers.append(deletedTracker);
}