From 6622a07ad88c7ca2eb34db66cc46f416f7b5286f Mon Sep 17 00:00:00 2001 From: artemp Date: Wed, 29 Oct 2014 14:35:58 -0400 Subject: [PATCH] simplify - remove before/afterParse and create Parser on stack in worker thread --- include/mbgl/map/tile_data.hpp | 2 -- include/mbgl/map/vector_tile_data.hpp | 6 ------ src/map/tile_data.cpp | 10 ++-------- src/map/vector_tile_data.cpp | 12 +++--------- 4 files changed, 5 insertions(+), 25 deletions(-) diff --git a/include/mbgl/map/tile_data.hpp b/include/mbgl/map/tile_data.hpp index b83f0316e..70297c7f3 100644 --- a/include/mbgl/map/tile_data.hpp +++ b/include/mbgl/map/tile_data.hpp @@ -53,9 +53,7 @@ public: } // Override this in the child class. - virtual void beforeParse(); virtual void parse() = 0; - virtual void afterParse(); virtual void render(Painter &painter, util::ptr layer_desc, const mat4 &matrix) = 0; virtual bool hasData(StyleLayer const& layer_desc) const = 0; diff --git a/include/mbgl/map/vector_tile_data.hpp b/include/mbgl/map/vector_tile_data.hpp index 1fbacab3d..9f611fd69 100644 --- a/include/mbgl/map/vector_tile_data.hpp +++ b/include/mbgl/map/vector_tile_data.hpp @@ -28,10 +28,7 @@ class VectorTileData : public TileData { public: VectorTileData(Tile::ID id, Map &map, const util::ptr &source); ~VectorTileData(); - - virtual void beforeParse(); virtual void parse(); - virtual void afterParse(); virtual void render(Painter &painter, util::ptr layer_desc, const mat4 &matrix); virtual bool hasData(StyleLayer const& layer_desc) const; @@ -49,9 +46,6 @@ protected: // Holds the buckets of this tile. // They contain the location offsets in the buffers stored above std::unordered_map> buckets; - - std::unique_ptr parser; - public: const float depth; }; diff --git a/src/map/tile_data.cpp b/src/map/tile_data.cpp index 7e4d1a1de..bb3573ce2 100644 --- a/src/map/tile_data.cpp +++ b/src/map/tile_data.cpp @@ -79,11 +79,8 @@ void TileData::cancel() { } } -void TileData::beforeParse() {} - -void TileData::reparse() { - beforeParse(); - +void TileData::reparse() +{ // We're creating a new work request. The work request deletes itself after it executed // the after work handler new uv::work>( @@ -92,10 +89,7 @@ void TileData::reparse() { tile->parse(); }, [](util::ptr &tile) { - tile->afterParse(); tile->map.update(); }, shared_from_this()); } - -void TileData::afterParse() {} diff --git a/src/map/vector_tile_data.cpp b/src/map/vector_tile_data.cpp index 4d9d2a544..80ad3a3fc 100644 --- a/src/map/vector_tile_data.cpp +++ b/src/map/vector_tile_data.cpp @@ -17,10 +17,6 @@ VectorTileData::~VectorTileData() { map.getGlyphAtlas().removeGlyphs(id.to_uint64()); } -void VectorTileData::beforeParse() { - parser = std::make_unique(data, *this, map.getStyle(), map.getGlyphAtlas(), - map.getGlyphStore(), map.getSpriteAtlas(), map.getSprite()); -} void VectorTileData::parse() { if (state != State::loaded) { @@ -31,7 +27,9 @@ void VectorTileData::parse() { // Parsing creates state that is encapsulated in TileParser. While parsing, // the TileParser object writes results into this objects. All other state // is going to be discarded afterwards. - parser->parse(); + TileParser parser(data, *this, map.getStyle(), map.getGlyphAtlas(), + map.getGlyphStore(), map.getSpriteAtlas(), map.getSprite()); + parser.parse(); } catch (const std::exception& ex) { #if defined(DEBUG) fprintf(stderr, "[%p] exception [%d/%d/%d]... failed: %s\n", this, id.z, id.x, id.y, ex.what()); @@ -45,10 +43,6 @@ void VectorTileData::parse() { } } -void VectorTileData::afterParse() { - parser.reset(); -} - void VectorTileData::render(Painter &painter, util::ptr layer_desc, const mat4 &matrix) { if (state == State::parsed && layer_desc->bucket) { auto databucket_it = buckets.find(layer_desc->bucket->name);