Commit 49e1af1f authored by Ronan's avatar Ronan

feat(PropertyContainer): increase performance => avoid private allocation if not used in childs

parent 21a5f1c0
......@@ -268,6 +268,7 @@ else()
"-Wfloat-equal"
"-Winit-self"
"-Wno-error=deprecated-declarations"
"-Wnon-virtual-dtor"
"-Wpointer-arith"
"-Wuninitialized"
"-Wunused"
......@@ -284,7 +285,7 @@ else()
list(APPEND STRICT_OPTIONS_C "-fno-inline-small-functions")
endif()
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
list(APPEND STRICT_OPTIONS_CPP "-Qunused-arguments" "-Wno-array-bounds -Wdelete-non-virtual-dtor")
list(APPEND STRICT_OPTIONS_CPP "-Qunused-arguments" "-Wno-array-bounds")
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
list(APPEND STRICT_OPTIONS_CXX "-x c++")
......
......@@ -17,12 +17,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "linphone/utils/utils.h"
#include "address-p.h"
#include "address/identity-address.h"
#include "c-wrapper/c-wrapper.h"
#include "c-wrapper/internal/c-sal.h"
#include "containers/lru-cache.h"
#include "logger/logger.h"
......
......@@ -36,14 +36,14 @@ public:
// -----------------------------------------------------------------------------
PropertyContainer::PropertyContainer () : mPrivate(new PropertyContainerPrivate) {}
PropertyContainer::PropertyContainer () : mPrivate(nullptr) {}
/*
* Empty copy constructor. Don't change this pattern.
* PropertyContainer is an Entity component, not a simple structure.
* An Entity is UNIQUE.
*/
PropertyContainer::PropertyContainer (const PropertyContainer &) : mPrivate(new PropertyContainerPrivate) {}
PropertyContainer::PropertyContainer (const PropertyContainer &) : mPrivate(nullptr) {}
PropertyContainer::~PropertyContainer () {
delete mPrivate;
......@@ -54,19 +54,23 @@ PropertyContainer &PropertyContainer::operator= (const PropertyContainer &) {
}
Variant PropertyContainer::getProperty (const string &name) const {
L_D();
auto it = d->properties.find(name);
return it == d->properties.cend() ? Variant() : it->second;
if (!mPrivate)
return Variant();
auto &properties = mPrivate->properties;
auto it = properties.find(name);
return it == properties.cend() ? Variant() : it->second;
}
void PropertyContainer::setProperty (const string &name, const Variant &value) {
L_D();
d->properties[name] = value;
if (!mPrivate)
mPrivate = new PropertyContainerPrivate();
mPrivate->properties[name] = value;
}
void PropertyContainer::setProperty (const string &name, Variant &&value) {
L_D();
d->properties[name] = move(value);
if (!mPrivate)
mPrivate = new PropertyContainerPrivate();
mPrivate->properties[name] = move(value);
}
LINPHONE_END_NAMESPACE
......@@ -41,9 +41,7 @@ public:
void setProperty (const std::string &name, Variant &&value);
private:
PropertyContainerPrivate *mPrivate = nullptr;
L_DECLARE_PRIVATE(PropertyContainer);
PropertyContainerPrivate *mPrivate;
};
LINPHONE_END_NAMESPACE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment