Hi, I have submitted a patch for review:
https://gerrit.libreoffice.org/3074 To pull it, you can do: git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/74/3074/1 fdo#62525: use cow_wrapper for FontAttribute Change-Id: Ic07da7c7cf225a910e6f0fa4f6d20c4700e7ec7a --- M drawinglayer/inc/drawinglayer/attribute/fontattribute.hxx M drawinglayer/source/attribute/fontattribute.cxx 2 files changed, 31 insertions(+), 63 deletions(-) diff --git a/drawinglayer/inc/drawinglayer/attribute/fontattribute.hxx b/drawinglayer/inc/drawinglayer/attribute/fontattribute.hxx index 36686fe..b49ab83 100644 --- a/drawinglayer/inc/drawinglayer/attribute/fontattribute.hxx +++ b/drawinglayer/inc/drawinglayer/attribute/fontattribute.hxx @@ -21,6 +21,7 @@ #define INCLUDED_DRAWINGLAYER_ATTRIBUTE_FONTATTRIBUTE_HXX #include <drawinglayer/drawinglayerdllapi.h> +#include <o3tl/cow_wrapper.hxx> ////////////////////////////////////////////////////////////////////////////// // predefines @@ -44,8 +45,11 @@ */ class DRAWINGLAYER_DLLPUBLIC FontAttribute { + public: + typedef o3tl::cow_wrapper< ImpFontAttribute > ImplType; + private: - ImpFontAttribute* mpFontAttribute; + ImplType mpFontAttribute; public: /// constructors/assignmentoperator/destructor diff --git a/drawinglayer/source/attribute/fontattribute.cxx b/drawinglayer/source/attribute/fontattribute.cxx index 627fb6c..c2f23a7 100644 --- a/drawinglayer/source/attribute/fontattribute.cxx +++ b/drawinglayer/source/attribute/fontattribute.cxx @@ -29,9 +29,6 @@ class ImpFontAttribute { public: - // refcounter - sal_uInt32 mnRefCount; - /// core data String maFamilyName; // Font Family Name String maStyleName; // Font Style Name @@ -57,8 +54,7 @@ bool bOutline, bool bRTL, bool bBiDiStrong) - : mnRefCount(0), - maFamilyName(rFamilyName), + : maFamilyName(rFamilyName), maStyleName(rStyleName), mnWeight(nWeight), mbSymbol(bSymbol), @@ -68,6 +64,20 @@ mbRTL(bRTL), mbBiDiStrong(bBiDiStrong), mbMonospaced(bMonospaced) + { + } + + ImpFontAttribute() + : maFamilyName(String()), + maStyleName(String()), + mnWeight(0), + mbSymbol(false), + mbVertical(false), + mbItalic(false), + mbOutline(false), + mbRTL(false), + mbBiDiStrong(false), + mbMonospaced(false) { } @@ -96,25 +106,13 @@ && getBiDiStrong() == rCompare.getBiDiStrong() && getMonospaced() == rCompare.getMonospaced()); } - - static ImpFontAttribute* get_global_default() - { - static ImpFontAttribute* pDefault = 0; - - if(!pDefault) - { - pDefault = new ImpFontAttribute( - String(), String(), - 0, - false, false, false, false, false, false, false); - - // never delete; start with RefCount 1, not 0 - pDefault->mnRefCount++; - } - - return pDefault; - } }; + + namespace + { + struct theGlobalDefault : + public rtl::Static< FontAttribute::ImplType, theGlobalDefault > {}; + } FontAttribute::FontAttribute( const String& rFamilyName, @@ -127,73 +125,39 @@ bool bOutline, bool bRTL, bool bBiDiStrong) - : mpFontAttribute(new ImpFontAttribute( + : mpFontAttribute(ImpFontAttribute( rFamilyName, rStyleName, nWeight, bSymbol, bVertical, bItalic, bMonospaced, bOutline, bRTL, bBiDiStrong)) { } FontAttribute::FontAttribute() - : mpFontAttribute(ImpFontAttribute::get_global_default()) + : mpFontAttribute(theGlobalDefault::get()) { - mpFontAttribute->mnRefCount++; } FontAttribute::FontAttribute(const FontAttribute& rCandidate) : mpFontAttribute(rCandidate.mpFontAttribute) { - mpFontAttribute->mnRefCount++; } FontAttribute::~FontAttribute() { - if(mpFontAttribute->mnRefCount) - { - mpFontAttribute->mnRefCount--; - } - else - { - delete mpFontAttribute; - } } bool FontAttribute::isDefault() const { - return mpFontAttribute == ImpFontAttribute::get_global_default(); + return mpFontAttribute.same_object(theGlobalDefault::get()); } FontAttribute& FontAttribute::operator=(const FontAttribute& rCandidate) { - if(rCandidate.mpFontAttribute != mpFontAttribute) - { - if(mpFontAttribute->mnRefCount) - { - mpFontAttribute->mnRefCount--; - } - else - { - delete mpFontAttribute; - } - - mpFontAttribute = rCandidate.mpFontAttribute; - mpFontAttribute->mnRefCount++; - } - + mpFontAttribute = rCandidate.mpFontAttribute; return *this; } bool FontAttribute::operator==(const FontAttribute& rCandidate) const { - if(rCandidate.mpFontAttribute == mpFontAttribute) - { - return true; - } - - if(rCandidate.isDefault() != isDefault()) - { - return false; - } - - return (*rCandidate.mpFontAttribute == *mpFontAttribute); + return rCandidate.mpFontAttribute == mpFontAttribute; } const String& FontAttribute::getFamilyName() const -- To view, visit https://gerrit.libreoffice.org/3074 To unsubscribe, visit https://gerrit.libreoffice.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic07da7c7cf225a910e6f0fa4f6d20c4700e7ec7a 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