Hi, I have submitted a patch for review:
https://gerrit.libreoffice.org/2945 To pull it, you can do: git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/45/2945/1 fdo#62525: use cow_wrapper for SdrShadowAttribute Thanks to Thorsten. Change-Id: I2713bacd10538dfe177cb975a9633dd65285c6fa --- M drawinglayer/inc/drawinglayer/attribute/sdrshadowattribute.hxx M drawinglayer/source/attribute/sdrshadowattribute.cxx 2 files changed, 26 insertions(+), 63 deletions(-) diff --git a/drawinglayer/inc/drawinglayer/attribute/sdrshadowattribute.hxx b/drawinglayer/inc/drawinglayer/attribute/sdrshadowattribute.hxx index 91657cd..ee1f362 100644 --- a/drawinglayer/inc/drawinglayer/attribute/sdrshadowattribute.hxx +++ b/drawinglayer/inc/drawinglayer/attribute/sdrshadowattribute.hxx @@ -21,6 +21,7 @@ #define INCLUDED_DRAWINGLAYER_ATTRIBUTE_SDRSHADOWATTRIBUTE_HXX #include <drawinglayer/drawinglayerdllapi.h> +#include <o3tl/cow_wrapper.hxx> ////////////////////////////////////////////////////////////////////////////// // predefines @@ -42,8 +43,11 @@ { class DRAWINGLAYER_DLLPUBLIC SdrShadowAttribute { + public: + typedef o3tl::cow_wrapper< ImpSdrShadowAttribute > ImplType; + private: - ImpSdrShadowAttribute* mpSdrShadowAttribute; + ImplType mpSdrShadowAttribute; public: /// constructors/assignmentoperator/destructor diff --git a/drawinglayer/source/attribute/sdrshadowattribute.cxx b/drawinglayer/source/attribute/sdrshadowattribute.cxx index f6b5e49..9705f6a 100644 --- a/drawinglayer/source/attribute/sdrshadowattribute.cxx +++ b/drawinglayer/source/attribute/sdrshadowattribute.cxx @@ -20,6 +20,7 @@ #include <drawinglayer/attribute/sdrshadowattribute.hxx> #include <basegfx/vector/b2dvector.hxx> #include <basegfx/color/bcolor.hxx> +#include <rtl/instance.hxx> ////////////////////////////////////////////////////////////////////////////// @@ -30,9 +31,6 @@ class ImpSdrShadowAttribute { public: - // refcounter - sal_uInt32 mnRefCount; - // shadow definitions basegfx::B2DVector maOffset; // shadow offset 1/100th mm double mfTransparence; // [0.0 .. 1.0], 0.0==no transp. @@ -42,10 +40,16 @@ const basegfx::B2DVector& rOffset, double fTransparence, const basegfx::BColor& rColor) - : mnRefCount(0), - maOffset(rOffset), + : maOffset(rOffset), mfTransparence(fTransparence), maColor(rColor) + { + } + + ImpSdrShadowAttribute() + : maOffset(basegfx::B2DVector()), + mfTransparence(0.0), + maColor(basegfx::BColor()) { } @@ -60,97 +64,52 @@ && getTransparence() == rCandidate.getTransparence() && getColor() == rCandidate.getColor()); } - - static ImpSdrShadowAttribute* get_global_default() - { - static ImpSdrShadowAttribute* pDefault = 0; - - if(!pDefault) - { - pDefault = new ImpSdrShadowAttribute( - basegfx::B2DVector(), - 0.0, - basegfx::BColor()); - - // never delete; start with RefCount 1, not 0 - pDefault->mnRefCount++; - } - - return pDefault; - } }; + + namespace + { + struct theGlobalDefault : + public rtl::Static< SdrShadowAttribute::ImplType, theGlobalDefault > {}; + } + SdrShadowAttribute::SdrShadowAttribute( const basegfx::B2DVector& rOffset, double fTransparence, const basegfx::BColor& rColor) - : mpSdrShadowAttribute(new ImpSdrShadowAttribute( + : mpSdrShadowAttribute(ImpSdrShadowAttribute( rOffset, fTransparence, rColor)) { } SdrShadowAttribute::SdrShadowAttribute() - : mpSdrShadowAttribute(ImpSdrShadowAttribute::get_global_default()) + : mpSdrShadowAttribute(theGlobalDefault::get()) { - mpSdrShadowAttribute->mnRefCount++; } SdrShadowAttribute::SdrShadowAttribute(const SdrShadowAttribute& rCandidate) : mpSdrShadowAttribute(rCandidate.mpSdrShadowAttribute) { - mpSdrShadowAttribute->mnRefCount++; } SdrShadowAttribute::~SdrShadowAttribute() { - if(mpSdrShadowAttribute->mnRefCount) - { - mpSdrShadowAttribute->mnRefCount--; - } - else - { - delete mpSdrShadowAttribute; - } } bool SdrShadowAttribute::isDefault() const { - return mpSdrShadowAttribute == ImpSdrShadowAttribute::get_global_default(); + return mpSdrShadowAttribute.same_object(theGlobalDefault::get()); } SdrShadowAttribute& SdrShadowAttribute::operator=(const SdrShadowAttribute& rCandidate) { - if(rCandidate.mpSdrShadowAttribute != mpSdrShadowAttribute) - { - if(mpSdrShadowAttribute->mnRefCount) - { - mpSdrShadowAttribute->mnRefCount--; - } - else - { - delete mpSdrShadowAttribute; - } - - mpSdrShadowAttribute = rCandidate.mpSdrShadowAttribute; - mpSdrShadowAttribute->mnRefCount++; - } - + mpSdrShadowAttribute = rCandidate.mpSdrShadowAttribute; return *this; } bool SdrShadowAttribute::operator==(const SdrShadowAttribute& rCandidate) const { - if(rCandidate.mpSdrShadowAttribute == mpSdrShadowAttribute) - { - return true; - } - - if(rCandidate.isDefault() != isDefault()) - { - return false; - } - - return (*rCandidate.mpSdrShadowAttribute == *mpSdrShadowAttribute); + return mpSdrShadowAttribute == rCandidate.mpSdrShadowAttribute; } const basegfx::B2DVector& SdrShadowAttribute::getOffset() const -- To view, visit https://gerrit.libreoffice.org/2945 To unsubscribe, visit https://gerrit.libreoffice.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2713bacd10538dfe177cb975a9633dd65285c6fa Gerrit-PatchSet: 1 Gerrit-Project: core Gerrit-Branch: master Gerrit-Owner: Thomas Arnhold <tho...@arnhold.org> _______________________________________________ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice