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.
This commit is contained in:
John Firebaugh
2015-05-13 12:28:39 -07:00
parent e6eb6c7fe4
commit b334b7ee4e
2 changed files with 6 additions and 13 deletions

View File

@@ -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;
}

View File

@@ -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);