[core] Avoid making a new copy of layers for redoPlacement

This commit is contained in:
John Firebaugh
2015-12-04 12:26:21 -08:00
parent cdd129335c
commit 203b443d26
5 changed files with 15 additions and 16 deletions

View File

@@ -31,13 +31,16 @@ TileWorker::~TileWorker() {
glyphAtlas.removeGlyphs(reinterpret_cast<uintptr_t>(this));
}
TileParseResult TileWorker::parseAllLayers(std::vector<std::unique_ptr<StyleLayer>> layers,
TileParseResult TileWorker::parseAllLayers(std::vector<std::unique_ptr<StyleLayer>> layers_,
const GeometryTile& geometryTile,
PlacementConfig config) {
// We're doing a fresh parse of the tile, because the underlying data has changed.
pending.clear();
partialParse = false;
// Store the layers for use in redoPlacement.
layers = std::move(layers_);
// Reset the collision tile so we have a clean slate; we're placing all features anyway.
collisionTile = std::make_unique<CollisionTile>(config);
@@ -46,10 +49,10 @@ TileParseResult TileWorker::parseAllLayers(std::vector<std::unique_ptr<StyleLaye
std::set<std::string> parsed;
for (auto i = layers.rbegin(); i != layers.rend(); i++) {
std::unique_ptr<StyleLayer> layer = std::move(*i);
const StyleLayer* layer = i->get();
if (parsed.find(layer->bucketName()) == parsed.end()) {
parsed.emplace(layer->bucketName());
parseLayer(std::move(layer), geometryTile);
parseLayer(layer, geometryTile);
}
}
@@ -89,7 +92,6 @@ TileParseResult TileWorker::parsePendingLayers() {
}
void TileWorker::redoPlacement(
std::vector<std::unique_ptr<StyleLayer>> layers,
const std::unordered_map<std::string, std::unique_ptr<Bucket>>* buckets,
PlacementConfig config) {
@@ -104,7 +106,7 @@ void TileWorker::redoPlacement(
}
}
void TileWorker::parseLayer(std::unique_ptr<StyleLayer> layer, const GeometryTile& geometryTile) {
void TileWorker::parseLayer(const StyleLayer* layer, const GeometryTile& geometryTile) {
// Cancel early when parsing.
if (state == TileData::State::obsolete)
return;
@@ -145,7 +147,7 @@ void TileWorker::parseLayer(std::unique_ptr<StyleLayer> layer, const GeometryTil
if (layer->type == StyleLayerType::Symbol && partialParse) {
// We cannot parse this bucket yet. Instead, we're saving it for later.
pending.emplace_back(std::move(layer), std::move(bucket));
pending.emplace_back(layer, std::move(bucket));
} else {
insertBucket(layer->bucketName(), std::move(bucket));
}

View File

@@ -51,12 +51,11 @@ public:
TileParseResult parsePendingLayers();
void redoPlacement(std::vector<std::unique_ptr<StyleLayer>>,
const std::unordered_map<std::string, std::unique_ptr<Bucket>>*,
void redoPlacement(const std::unordered_map<std::string, std::unique_ptr<Bucket>>*,
PlacementConfig);
private:
void parseLayer(std::unique_ptr<StyleLayer>, const GeometryTile&);
void parseLayer(const StyleLayer*, const GeometryTile&);
void insertBucket(const std::string& name, std::unique_ptr<Bucket>);
const TileID id;
@@ -69,11 +68,12 @@ private:
bool partialParse = false;
std::vector<std::unique_ptr<StyleLayer>> layers;
std::unique_ptr<CollisionTile> collisionTile;
// Contains buckets that we couldn't parse so far due to missing resources.
// They will be attempted on subsequent parses.
std::list<std::pair<std::unique_ptr<StyleLayer>, std::unique_ptr<Bucket>>> pending;
std::list<std::pair<const StyleLayer*, std::unique_ptr<Bucket>>> pending;
// Temporary holder
TileParseResultBuckets result;

View File

@@ -166,7 +166,7 @@ void VectorTileData::redoPlacement(const PlacementConfig newConfig) {
void VectorTileData::redoPlacement() {
workRequest.reset();
workRequest = worker.redoPlacement(tileWorker, style.getLayers(), buckets, targetConfig, [this, config = targetConfig] {
workRequest = worker.redoPlacement(tileWorker, buckets, targetConfig, [this, config = targetConfig] {
workRequest.reset();
// Persist the configuration we just placed so that we can later check whether we need to

View File

@@ -55,11 +55,10 @@ public:
}
void redoPlacement(TileWorker* worker,
std::vector<std::unique_ptr<StyleLayer>> layers,
const std::unordered_map<std::string, std::unique_ptr<Bucket>>* buckets,
PlacementConfig config,
std::function<void()> callback) {
worker->redoPlacement(std::move(layers), buckets, config);
worker->redoPlacement(buckets, config);
callback();
}
};
@@ -103,13 +102,12 @@ Worker::parsePendingGeometryTileLayers(TileWorker& worker,
std::unique_ptr<WorkRequest>
Worker::redoPlacement(TileWorker& worker,
std::vector<std::unique_ptr<StyleLayer>> layers,
const std::unordered_map<std::string, std::unique_ptr<Bucket>>& buckets,
PlacementConfig config,
std::function<void()> callback) {
current = (current + 1) % threads.size();
return threads[current]->invokeWithCallback(&Worker::Impl::redoPlacement, callback, &worker,
std::move(layers), &buckets, config);
&buckets, config);
}
} // end namespace mbgl

View File

@@ -49,7 +49,6 @@ public:
std::function<void(TileParseResult)> callback);
Request redoPlacement(TileWorker&,
std::vector<std::unique_ptr<StyleLayer>>,
const std::unordered_map<std::string, std::unique_ptr<Bucket>>&,
PlacementConfig config,
std::function<void()> callback);