diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2016-11-23 17:31:47 +0100 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2016-11-24 10:21:01 +0000 |
commit | a7bc67e54c5dfc06893fdf87bf4565b8d4429f72 (patch) | |
tree | 9cedba726e81ec1ae6d8af8530b07e10e9e52804 | |
parent | f52d84f4c750dfdaba8f4f0c241994b7364ec5fc (diff) | |
download | qtlocation-a7bc67e54c5dfc06893fdf87bf4565b8d4429f72.tar.gz |
Fix for Unitary cache strategy support
This patch fixes the population phase of the cache to support
unitary strategy.
It also prevents a possible divide-by-zero error.
Change-Id: I4ab18041f8e908bd60eb581663fe34fbb01c4991
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r-- | src/location/maps/qcache3q_p.h | 4 | ||||
-rw-r--r-- | src/location/maps/qgeofiletilecache.cpp | 36 |
2 files changed, 25 insertions, 15 deletions
diff --git a/src/location/maps/qcache3q_p.h b/src/location/maps/qcache3q_p.h index cd21961a..148c1f8b 100644 --- a/src/location/maps/qcache3q_p.h +++ b/src/location/maps/qcache3q_p.h @@ -145,7 +145,7 @@ private: QHash<Key, Node *> lookup_; public: - explicit QCache3Q(int maxCost = 100, int minRecent = -1, int maxOldPopular = -1); + explicit QCache3Q(int maxCost = 0, int minRecent = -1, int maxOldPopular = -1); inline ~QCache3Q() { clear(); delete q1_; delete q2_; delete q3_; delete q1_evicted_; } inline int maxCost() const { return maxCost_; } @@ -398,7 +398,7 @@ void QCache3Q<Key,T,EvPolicy>::rebalance() } else { Node *n = q2_->l; unlink(n); - if (n->pop > (q2_->pop / q2_->size)) { + if (q2_->size && n->pop > (q2_->pop / q2_->size)) { link_front(n, q3_); } else { EvPolicy::aboutToBeEvicted(n->k, n->v); diff --git a/src/location/maps/qgeofiletilecache.cpp b/src/location/maps/qgeofiletilecache.cpp index 911e9865..49e9dfff 100644 --- a/src/location/maps/qgeofiletilecache.cpp +++ b/src/location/maps/qgeofiletilecache.cpp @@ -120,20 +120,26 @@ void QGeoFileTileCache::init() QDir::root().mkpath(directory_); // default values - if (costStrategyDisk_ == ByteSize) - setMaxDiskUsage(50 * 1024 * 1024); - else - setMaxDiskUsage(1000); + if (!diskCache_.maxCost()) { // If setMaxDiskUsage has not been called yet + if (costStrategyDisk_ == ByteSize) + setMaxDiskUsage(50 * 1024 * 1024); + else + setMaxDiskUsage(1000); + } - if (costStrategyMemory_ == ByteSize) - setMaxMemoryUsage(3 * 1024 * 1024); - else - setMaxMemoryUsage(100); + if (!memoryCache_.maxCost()) { // If setMaxMemoryUsage has not been called yet + if (costStrategyMemory_ == ByteSize) + setMaxMemoryUsage(3 * 1024 * 1024); + else + setMaxMemoryUsage(100); + } - if (costStrategyTexture_ == ByteSize) - setExtraTextureUsage(6 * 1024 * 1024); - else - setExtraTextureUsage(30); // byte size of texture is >> compressed image, hence unitary cost should be lower + if (!textureCache_.maxCost()) { // If setExtraTextureUsage has not been called yet + if (costStrategyTexture_ == ByteSize) + setExtraTextureUsage(6 * 1024 * 1024); + else + setExtraTextureUsage(30); // byte size of texture is >> compressed image, hence unitary cost should be lower + } loadTiles(); } @@ -172,7 +178,11 @@ void QGeoFileTileCache::loadTiles() QFileInfo fi(tileDisk->filename); specs.append(spec); queue.append(tileDisk); - costs.append(fi.size()); + if (costStrategyDisk_ == ByteSize) + costs.append(fi.size()); + else + costs.append(1); + } } |