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() ...@@ -268,6 +268,7 @@ else()
"-Wfloat-equal" "-Wfloat-equal"
"-Winit-self" "-Winit-self"
"-Wno-error=deprecated-declarations" "-Wno-error=deprecated-declarations"
"-Wnon-virtual-dtor"
"-Wpointer-arith" "-Wpointer-arith"
"-Wuninitialized" "-Wuninitialized"
"-Wunused" "-Wunused"
...@@ -284,7 +285,7 @@ else() ...@@ -284,7 +285,7 @@ else()
list(APPEND STRICT_OPTIONS_C "-fno-inline-small-functions") list(APPEND STRICT_OPTIONS_C "-fno-inline-small-functions")
endif() endif()
if(CMAKE_C_COMPILER_ID MATCHES "Clang") 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() endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
list(APPEND STRICT_OPTIONS_CXX "-x c++") list(APPEND STRICT_OPTIONS_CXX "-x c++")
......
...@@ -17,12 +17,9 @@ ...@@ -17,12 +17,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "linphone/utils/utils.h"
#include "address-p.h" #include "address-p.h"
#include "address/identity-address.h" #include "address/identity-address.h"
#include "c-wrapper/c-wrapper.h" #include "c-wrapper/c-wrapper.h"
#include "c-wrapper/internal/c-sal.h"
#include "containers/lru-cache.h" #include "containers/lru-cache.h"
#include "logger/logger.h" #include "logger/logger.h"
......
...@@ -36,14 +36,14 @@ public: ...@@ -36,14 +36,14 @@ public:
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
PropertyContainer::PropertyContainer () : mPrivate(new PropertyContainerPrivate) {} PropertyContainer::PropertyContainer () : mPrivate(nullptr) {}
/* /*
* Empty copy constructor. Don't change this pattern. * Empty copy constructor. Don't change this pattern.
* PropertyContainer is an Entity component, not a simple structure. * PropertyContainer is an Entity component, not a simple structure.
* An Entity is UNIQUE. * An Entity is UNIQUE.
*/ */
PropertyContainer::PropertyContainer (const PropertyContainer &) : mPrivate(new PropertyContainerPrivate) {} PropertyContainer::PropertyContainer (const PropertyContainer &) : mPrivate(nullptr) {}
PropertyContainer::~PropertyContainer () { PropertyContainer::~PropertyContainer () {
delete mPrivate; delete mPrivate;
...@@ -54,19 +54,23 @@ PropertyContainer &PropertyContainer::operator= (const PropertyContainer &) { ...@@ -54,19 +54,23 @@ PropertyContainer &PropertyContainer::operator= (const PropertyContainer &) {
} }
Variant PropertyContainer::getProperty (const string &name) const { Variant PropertyContainer::getProperty (const string &name) const {
L_D(); if (!mPrivate)
auto it = d->properties.find(name); return Variant();
return it == d->properties.cend() ? Variant() : it->second; 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) { void PropertyContainer::setProperty (const string &name, const Variant &value) {
L_D(); if (!mPrivate)
d->properties[name] = value; mPrivate = new PropertyContainerPrivate();
mPrivate->properties[name] = value;
} }
void PropertyContainer::setProperty (const string &name, Variant &&value) { void PropertyContainer::setProperty (const string &name, Variant &&value) {
L_D(); if (!mPrivate)
d->properties[name] = move(value); mPrivate = new PropertyContainerPrivate();
mPrivate->properties[name] = move(value);
} }
LINPHONE_END_NAMESPACE LINPHONE_END_NAMESPACE
...@@ -41,9 +41,7 @@ public: ...@@ -41,9 +41,7 @@ public:
void setProperty (const std::string &name, Variant &&value); void setProperty (const std::string &name, Variant &&value);
private: private:
PropertyContainerPrivate *mPrivate = nullptr; PropertyContainerPrivate *mPrivate;
L_DECLARE_PRIVATE(PropertyContainer);
}; };
LINPHONE_END_NAMESPACE 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