Skip to content

Commit

Permalink
Merge pull request #1633 from Karry/fix-uninitialized
Browse files Browse the repository at this point in the history
initialize age of oldest key entry
  • Loading branch information
Framstag authored Dec 29, 2024
2 parents 242e6a5 + d4304f5 commit dddcdf0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion libosmscout-client-qt/include/osmscoutclientqt/TileCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ QDebug& operator<<(QDebug &out, const TileCacheKey &key);
*/
struct TileCacheVal
{
std::chrono::steady_clock::time_point lastAccess;
using clock=std::chrono::steady_clock;
clock::time_point lastAccess;
QImage image;
size_t epoch;
};
Expand Down
12 changes: 6 additions & 6 deletions libosmscout-client-qt/src/osmscoutclientqt/TileCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ TileCacheVal TileCache::get(uint32_t zoomLevel, uint32_t x, uint32_t y)
TileCacheKey key = {zoomLevel, x, y};
if (!tiles.contains(key)){
qWarning() << this << "No tile in cache for key " << key;
return {std::chrono::steady_clock::now(), QImage(), epoch}; // throw std::underflow_error ?
return {TileCacheVal::clock::now(), QImage(), epoch}; // throw std::underflow_error ?
}
TileCacheVal val = tiles.value(key);
val.lastAccess = std::chrono::steady_clock::now();
val.lastAccess = TileCacheVal::clock::now();
tiles.insert(key, val);
return val;
}
Expand All @@ -190,7 +190,7 @@ void TileCache::put(uint32_t zoomLevel, uint32_t x, uint32_t y, const QImage &im
{
removeRequest(zoomLevel, x, y);
TileCacheKey key = {zoomLevel, x, y};
TileCacheVal val = {std::chrono::steady_clock::now(), image, epoch};
TileCacheVal val = {TileCacheVal::clock::now(), image, epoch};

#ifdef DEBUG_TILE_CACHE
qDebug() << this << "inserting tile" << key;
Expand Down Expand Up @@ -224,10 +224,10 @@ void TileCache::cleanupCache(uint32_t maxRemove, const std::chrono::milliseconds
#endif

uint32_t removed = 0;
std::chrono::steady_clock::duration oldest;
auto oldest=TileCacheVal::clock::duration::zero();
TileCacheKey key;
TileCacheKey oldestKey;
auto now = std::chrono::steady_clock::now();
auto now = TileCacheVal::clock::now();

QMutableHashIterator<TileCacheKey, TileCacheVal> it(tiles);
while (it.hasNext() && removed < maxRemove){
Expand All @@ -242,7 +242,7 @@ void TileCache::cleanupCache(uint32_t maxRemove, const std::chrono::milliseconds
oldestKey = key;
}

if (elapsed > duration_cast<std::chrono::steady_clock::duration>(maximumLifetime)){
if (elapsed > duration_cast<TileCacheVal::clock::duration>(maximumLifetime)){
#ifdef DEBUG_TILE_CACHE
qDebug() << this << "removing" << key;
#endif
Expand Down

0 comments on commit dddcdf0

Please sign in to comment.