summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-01-21 16:48:19 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-01-22 18:42:53 -0800
commit73ddff60ad808e8cc010775eb53fcb9ef38e9a84 (patch)
tree8a5a411997790b2b027aff1b5e4e93c38ff47766
parentbf48467b8c0a5b934253dadbc06c9dde4e643e53 (diff)
downloadqtlocation-mapboxgl-73ddff60ad808e8cc010775eb53fcb9ef38e9a84.tar.gz
[core] Avoid storing raw glyph data in addition to parsed representation
-rw-r--r--src/mbgl/text/glyph_pbf.cpp43
-rw-r--r--src/mbgl/text/glyph_pbf.hpp5
2 files changed, 17 insertions, 31 deletions
diff --git a/src/mbgl/text/glyph_pbf.cpp b/src/mbgl/text/glyph_pbf.cpp
index f6f0dca021..37b7cfc9fb 100644
--- a/src/mbgl/text/glyph_pbf.cpp
+++ b/src/mbgl/text/glyph_pbf.cpp
@@ -74,38 +74,29 @@ GlyphPBF::GlyphPBF(GlyphStore* store,
return "";
});
- auto requestCallback = [this, store, fontStack, glyphRange](Response res) {
+ FileSource* fs = util::ThreadContext::getFileSource();
+ req = fs->request({ Resource::Kind::Glyphs, url }, [this, store, fontStack, glyphRange](Response res) {
if (res.error) {
observer->onGlyphsError(fontStack, glyphRange, std::make_exception_ptr(std::runtime_error(res.error->message)));
- } else if (data != res.data || (*data != *res.data)) {
- data = res.data;
- parse(store, fontStack, glyphRange);
+ return;
}
- };
-
- FileSource* fs = util::ThreadContext::getFileSource();
- req = fs->request({ Resource::Kind::Glyphs, url }, requestCallback);
-}
-GlyphPBF::~GlyphPBF() = default;
-
-void GlyphPBF::parse(GlyphStore* store, const std::string& fontStack, const GlyphRange& glyphRange) {
- assert(data);
- if (data->empty()) {
- // If there is no data, this means we either haven't
- // received any data.
- return;
- }
+ if (res.notModified) {
+ return;
+ }
- try {
- parseGlyphPBF(**store->getFontStack(fontStack), *data);
- } catch (...) {
- observer->onGlyphsError(fontStack, glyphRange, std::current_exception());
- return;
- }
+ try {
+ parseGlyphPBF(**store->getFontStack(fontStack), *res.data);
+ } catch (...) {
+ observer->onGlyphsError(fontStack, glyphRange, std::current_exception());
+ return;
+ }
- parsed = true;
- observer->onGlyphsLoaded(fontStack, glyphRange);
+ parsed = true;
+ observer->onGlyphsLoaded(fontStack, glyphRange);
+ });
}
+GlyphPBF::~GlyphPBF() = default;
+
} // namespace mbgl
diff --git a/src/mbgl/text/glyph_pbf.hpp b/src/mbgl/text/glyph_pbf.hpp
index e0f65e7789..9e2ee4eacf 100644
--- a/src/mbgl/text/glyph_pbf.hpp
+++ b/src/mbgl/text/glyph_pbf.hpp
@@ -28,13 +28,8 @@ public:
}
private:
- void parse(GlyphStore*, const std::string& fontStack, const GlyphRange&);
-
- std::shared_ptr<const std::string> data;
std::atomic<bool> parsed;
-
std::unique_ptr<FileRequest> req;
-
GlyphStore::Observer* observer = nullptr;
};