[core] Avoid storing raw glyph data in addition to parsed representation
This commit is contained in:
@@ -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);
|
||||
if (res.notModified) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
parseGlyphPBF(**store->getFontStack(fontStack), *res.data);
|
||||
} catch (...) {
|
||||
observer->onGlyphsError(fontStack, glyphRange, std::current_exception());
|
||||
return;
|
||||
}
|
||||
|
||||
parsed = true;
|
||||
observer->onGlyphsLoaded(fontStack, glyphRange);
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
try {
|
||||
parseGlyphPBF(**store->getFontStack(fontStack), *data);
|
||||
} catch (...) {
|
||||
observer->onGlyphsError(fontStack, glyphRange, std::current_exception());
|
||||
return;
|
||||
}
|
||||
|
||||
parsed = true;
|
||||
observer->onGlyphsLoaded(fontStack, glyphRange);
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user