summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin R. Miller <incanus@users.noreply.github.com>2015-04-22 17:29:32 -0700
committerJustin R. Miller <incanus@users.noreply.github.com>2015-04-22 17:29:32 -0700
commit6592017a73bf7f4168d158c57b074c1a155631a9 (patch)
tree83c239111ac86b9685a8ecb31bc71ca3def0f9c8
parentbf13b31f90cc5987347d0c41e7a966b0ebee1018 (diff)
parentb43ba4089cf5aefe86fde1dae2fd5c06bd7bf784 (diff)
downloadqtlocation-mapboxgl-6592017a73bf7f4168d158c57b074c1a155631a9.tar.gz
Merge pull request #1324 from mapbox/normalize-cache
fixes #1308: normalize tile memory cache keys & allow dupe inserts
-rw-r--r--src/mbgl/map/source.cpp6
-rw-r--r--src/mbgl/map/tile_cache.cpp9
2 files changed, 10 insertions, 5 deletions
diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp
index 3245bab2e3..9e318964b0 100644
--- a/src/mbgl/map/source.cpp
+++ b/src/mbgl/map/source.cpp
@@ -245,7 +245,7 @@ TileData::State Source::addTile(Map &map, Worker &worker,
}
if (!new_tile.data) {
- new_tile.data = cache.get(id.to_uint64());
+ new_tile.data = cache.get(normalized_id.to_uint64());
}
if (!new_tile.data) {
@@ -418,7 +418,7 @@ void Source::update(Map &map,
if (!obsolete) {
retain_data.insert(tile.data->id);
} else if (type != SourceType::Raster && tile.data->ready()) {
- tileCache.add(tile.id.to_uint64(), tile.data);
+ tileCache.add(tile.id.normalized().to_uint64(), tile.data);
}
return obsolete;
});
@@ -432,7 +432,7 @@ void Source::update(Map &map,
bool obsolete = retain_data.find(tile->id) == retain_data.end();
if (obsolete) {
- if (!tileCache.has(tile->id.to_uint64())) {
+ if (!tileCache.has(tile->id.normalized().to_uint64())) {
tile->cancel();
}
return true;
diff --git a/src/mbgl/map/tile_cache.cpp b/src/mbgl/map/tile_cache.cpp
index b64c8e2a6b..25aed6d15e 100644
--- a/src/mbgl/map/tile_cache.cpp
+++ b/src/mbgl/map/tile_cache.cpp
@@ -20,11 +20,16 @@ void TileCache::setSize(size_t size_) {
void TileCache::add(uint64_t key, std::shared_ptr<TileData> data) {
- assert(tiles.find(key) == tiles.end());
+ // insert new or query existing data
+ if (tiles.emplace(key, data).second) {
+ // remove existing data key
+ orderedKeys.remove(key);
+ }
- tiles.emplace(key, data);
+ // (re-)insert data key as newest
orderedKeys.push_back(key);
+ // purge oldest key/data if necessary
if (orderedKeys.size() > size) {
get(orderedKeys.front());
}