diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-10-16 16:14:55 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-10-26 15:54:27 +0100 |
commit | 5173bf1bb8d21054b0dd6251d23eb37323d6c525 (patch) | |
tree | d13536c22b8279e9fd7e8f4892596c42973170f3 /src/mbgl/util | |
parent | 4e3503ea6cf30c55a2cc86f78c4a607bd14f1c41 (diff) | |
download | qtlocation-mapboxgl-5173bf1bb8d21054b0dd6251d23eb37323d6c525.tar.gz |
[core] Make response data shared to avoid excessive copying
Diffstat (limited to 'src/mbgl/util')
-rw-r--r-- | src/mbgl/util/worker.cpp | 12 | ||||
-rw-r--r-- | src/mbgl/util/worker.hpp | 4 |
2 files changed, 8 insertions, 8 deletions
diff --git a/src/mbgl/util/worker.cpp b/src/mbgl/util/worker.cpp index 71c930b4ef..fc599713b3 100644 --- a/src/mbgl/util/worker.cpp +++ b/src/mbgl/util/worker.cpp @@ -16,8 +16,8 @@ class Worker::Impl { public: Impl() = default; - void parseRasterTile(RasterBucket* bucket, std::string data, std::function<void (TileParseResult)> callback) { - std::unique_ptr<util::Image> image(new util::Image(data)); + void parseRasterTile(RasterBucket* bucket, const std::shared_ptr<const std::string> data, std::function<void (TileParseResult)> callback) { + std::unique_ptr<util::Image> image(new util::Image(*data)); if (!(*image)) { callback(TileParseResult("error parsing raster image")); } @@ -29,9 +29,9 @@ public: callback(TileParseResult(TileData::State::parsed)); } - void parseVectorTile(TileWorker* worker, std::string data, std::function<void (TileParseResult)> callback) { + void parseVectorTile(TileWorker* worker, const std::shared_ptr<const std::string> data, std::function<void (TileParseResult)> callback) { try { - pbf tilePBF(reinterpret_cast<const unsigned char *>(data.data()), data.size()); + pbf tilePBF(reinterpret_cast<const unsigned char*>(data->data()), data->size()); callback(worker->parse(VectorTile(tilePBF))); } catch (const std::exception& ex) { callback(TileParseResult(ex.what())); @@ -61,12 +61,12 @@ Worker::Worker(std::size_t count) { Worker::~Worker() = default; -std::unique_ptr<WorkRequest> Worker::parseRasterTile(RasterBucket& bucket, std::string data, std::function<void (TileParseResult)> callback) { +std::unique_ptr<WorkRequest> Worker::parseRasterTile(RasterBucket& bucket, const std::shared_ptr<const std::string> data, std::function<void (TileParseResult)> callback) { current = (current + 1) % threads.size(); return threads[current]->invokeWithCallback(&Worker::Impl::parseRasterTile, callback, &bucket, data); } -std::unique_ptr<WorkRequest> Worker::parseVectorTile(TileWorker& worker, std::string data, std::function<void (TileParseResult)> callback) { +std::unique_ptr<WorkRequest> Worker::parseVectorTile(TileWorker& worker, const std::shared_ptr<const std::string> data, std::function<void (TileParseResult)> callback) { current = (current + 1) % threads.size(); return threads[current]->invokeWithCallback(&Worker::Impl::parseVectorTile, callback, &worker, data); } diff --git a/src/mbgl/util/worker.hpp b/src/mbgl/util/worker.hpp index 4e63b45abf..18b1bc92b1 100644 --- a/src/mbgl/util/worker.hpp +++ b/src/mbgl/util/worker.hpp @@ -33,12 +33,12 @@ public: Request parseRasterTile( RasterBucket&, - std::string data, + std::shared_ptr<const std::string> data, std::function<void (TileParseResult)> callback); Request parseVectorTile( TileWorker&, - std::string data, + std::shared_ptr<const std::string> data, std::function<void (TileParseResult)> callback); Request parseLiveTile( |