[core] Return {Source,Layer}::getID by value
Avoid dangling references in the following sequence:
auto& id = layer->getID();
layer->setMaxZoom(2);
std::cout << id;
The reference would be dangling because mutating the layer allocates a new Immutable impl, and there may be no references to the prior impl, which held the id.
This commit is contained in:
@@ -92,7 +92,7 @@ public:
|
||||
}
|
||||
|
||||
LayerType getType() const;
|
||||
const std::string& getID() const;
|
||||
std::string getID() const;
|
||||
|
||||
// Visibility
|
||||
VisibilityType getVisibility() const;
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
}
|
||||
|
||||
SourceType getType() const;
|
||||
const std::string& getID() const;
|
||||
std::string getID() const;
|
||||
optional<std::string> getAttribution() const;
|
||||
|
||||
// Private implementation
|
||||
|
||||
@@ -18,7 +18,7 @@ LayerType Layer::getType() const {
|
||||
return baseImpl->type;
|
||||
}
|
||||
|
||||
const std::string& Layer::getID() const {
|
||||
std::string Layer::getID() const {
|
||||
return baseImpl->id;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ SourceType Source::getType() const {
|
||||
return baseImpl->type;
|
||||
}
|
||||
|
||||
const std::string& Source::getID() const {
|
||||
std::string Source::getID() const {
|
||||
return baseImpl->id;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user