mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-02-14 00:28:42 +00:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user