RideCache load performance improvement

.. string manipulation using raw C since its simple character
   replacement, halved time over previous approach.

.. lookup rideitem in ridecache via binary search (lower_bound)
   rather than serial. Minor speed up.

.. Overall, loading should be noticeably quicker for most users.
This commit is contained in:
Mark Liversedge
2020-07-30 15:44:02 +01:00
parent 11092bf436
commit 7a4be49492
7 changed files with 85 additions and 38 deletions

View File

@@ -124,12 +124,12 @@ RideCache::RideCache(Context *context) : context(context)
}
}
// now sort it - we need to use find on it
qSort(rides_.begin(), rides_.end(), rideCacheLessThan);
// load the store - will unstale once cache restored
load();
// now sort it
qSort(rides_.begin(), rides_.end(), rideCacheLessThan);
// set model once we have the basics
model_ = new RideCacheModel(context, this);
@@ -152,6 +152,20 @@ RideCache::RideCache(Context *context) : context(context)
connect(&watcher, SIGNAL(progressValueChanged(int)), this, SLOT(progressing(int)));
}
struct comparerideitem { bool operator()(const RideItem *p1, const RideItem *p2) { return p1->dateTime < p2->dateTime; } };
int
RideCache::find(RideItem *dt)
{
// use lower_bound to binary search
QVector<RideItem*>::const_iterator i = std::lower_bound(rides_.begin(), rides_.end(), dt, comparerideitem());
int index = i - rides_.begin();
// did it find the right value?
if (index < 0 || index >= rides_.count() || rides_.at(index)->dateTime != dt->dateTime) return -1;
return index;
}
RideCache::~RideCache()
{
exiting = true;