diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2015-05-13 12:28:39 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2015-05-13 13:57:32 -0700 |
commit | b334b7ee4ef83b28635f6409db1d6ec8630da91d (patch) | |
tree | 0f1db507f5d961a80dda67c887c6fee598a2f149 /src | |
parent | e6eb6c7fe421abe1fa6d2ca0934847cf326fa222 (diff) | |
download | qtlocation-mapboxgl-b334b7ee4ef83b28635f6409db1d6ec8630da91d.tar.gz |
Remove unnecessary use of shared_from_this()
If the request is cancelled, the response callback won't be called, and
~Source ensures that the request is cancelled. So it's safe to bind
`this` in the lambda.
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/map/source.cpp | 16 | ||||
-rw-r--r-- | src/mbgl/map/source.hpp | 3 |
2 files changed, 6 insertions, 13 deletions
diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index e663ef3d58..afe775be30 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -144,11 +144,9 @@ void Source::load(const std::string& accessToken) { return; } - util::ptr<Source> source = shared_from_this(); - const std::string url = util::mapbox::normalizeSourceURL(info.url, accessToken); - req = Environment::Get().request({ Resource::Kind::JSON, url }, [source](const Response &res) { - source->clearRequest(); + req = Environment::Get().request({ Resource::Kind::JSON, url }, [this](const Response &res) { + req = nullptr; if (res.status != Response::Successful) { Log::Warning(Event::General, "Failed to load source TileJSON: %s", res.message.c_str()); @@ -163,10 +161,10 @@ void Source::load(const std::string& accessToken) { return; } - source->info.parseTileJSONProperties(d); - source->loaded = true; + info.parseTileJSONProperties(d); + loaded = true; - source->emitSourceLoaded(); + emitSourceLoaded(); }); } @@ -509,10 +507,6 @@ void Source::onLowMemory() { cache.clear(); } -void Source::clearRequest() { - req = nullptr; -} - void Source::setObserver(Observer* observer) { observer_ = observer; } diff --git a/src/mbgl/map/source.hpp b/src/mbgl/map/source.hpp index eb7950225d..15cc8a817b 100644 --- a/src/mbgl/map/source.hpp +++ b/src/mbgl/map/source.hpp @@ -51,7 +51,7 @@ public: std::string tileURL(const TileID& id, float pixelRatio) const; }; -class Source : public std::enable_shared_from_this<Source>, private util::noncopyable { +class Source : private util::noncopyable { public: class Observer { public: @@ -88,7 +88,6 @@ public: void setCacheSize(size_t); void onLowMemory(); - void clearRequest(); void setObserver(Observer* observer); |