[PATCH] fdo#62525: use cow_wrapper for FillBitmapAttribute
Thomas Arnhold (via Code Review)
gerrit at gerrit.libreoffice.org
Sat Mar 23 13:10:50 PDT 2013
Hi,
I have submitted a patch for review:
https://gerrit.libreoffice.org/2948
To pull it, you can do:
git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/48/2948/1
fdo#62525: use cow_wrapper for FillBitmapAttribute
Change-Id: I0f666d4baaf6dc4e9f7ea30a518a8904f01d749f
---
M drawinglayer/inc/drawinglayer/attribute/fillbitmapattribute.hxx
M drawinglayer/source/attribute/fillbitmapattribute.cxx
2 files changed, 24 insertions(+), 62 deletions(-)
diff --git a/drawinglayer/inc/drawinglayer/attribute/fillbitmapattribute.hxx b/drawinglayer/inc/drawinglayer/attribute/fillbitmapattribute.hxx
index ced46b3..851dc5e 100644
--- a/drawinglayer/inc/drawinglayer/attribute/fillbitmapattribute.hxx
+++ b/drawinglayer/inc/drawinglayer/attribute/fillbitmapattribute.hxx
@@ -21,6 +21,7 @@
#define INCLUDED_DRAWINGLAYER_ATTRIBUTE_FILLBITMAPATTRIBUTE_HXX
#include <drawinglayer/drawinglayerdllapi.h>
+#include <o3tl/cow_wrapper.hxx>
//////////////////////////////////////////////////////////////////////////////
// predefines
@@ -44,8 +45,11 @@
{
class DRAWINGLAYER_DLLPUBLIC FillBitmapAttribute
{
+ public:
+ typedef o3tl::cow_wrapper< ImpFillBitmapAttribute > ImplType;
+
private:
- ImpFillBitmapAttribute* mpFillBitmapAttribute;
+ ImplType mpFillBitmapAttribute;
public:
/// constructors/assignmentoperator/destructor
diff --git a/drawinglayer/source/attribute/fillbitmapattribute.cxx b/drawinglayer/source/attribute/fillbitmapattribute.cxx
index b315178..e2bedb4 100644
--- a/drawinglayer/source/attribute/fillbitmapattribute.cxx
+++ b/drawinglayer/source/attribute/fillbitmapattribute.cxx
@@ -29,9 +29,6 @@
class ImpFillBitmapAttribute
{
public:
- // refcounter
- sal_uInt32 mnRefCount;
-
// data definitions
BitmapEx maBitmapEx;
basegfx::B2DPoint maTopLeft;
@@ -45,11 +42,18 @@
const basegfx::B2DPoint& rTopLeft,
const basegfx::B2DVector& rSize,
bool bTiling)
- : mnRefCount(0),
- maBitmapEx(rBitmapEx),
+ : maBitmapEx(rBitmapEx),
maTopLeft(rTopLeft),
maSize(rSize),
mbTiling(bTiling)
+ {
+ }
+
+ ImpFillBitmapAttribute()
+ : maBitmapEx(BitmapEx()),
+ maTopLeft(basegfx::B2DPoint()),
+ maSize(basegfx::B2DVector()),
+ mbTiling(false)
{
}
@@ -66,33 +70,20 @@
const basegfx::B2DPoint& getTopLeft() const { return maTopLeft; }
const basegfx::B2DVector& getSize() const { return maSize; }
bool getTiling() const { return mbTiling; }
-
- static ImpFillBitmapAttribute* get_global_default()
- {
- static ImpFillBitmapAttribute* pDefault = 0;
-
- if(!pDefault)
- {
- pDefault = new ImpFillBitmapAttribute(
- BitmapEx(),
- basegfx::B2DPoint(),
- basegfx::B2DVector(),
- false);
-
- // never delete; start with RefCount 1, not 0
- pDefault->mnRefCount++;
- }
-
- return pDefault;
- }
};
+
+ namespace
+ {
+ struct theGlobalDefault :
+ public rtl::Static< FillBitmapAttribute::ImplType, theGlobalDefault > {};
+ }
FillBitmapAttribute::FillBitmapAttribute(
const BitmapEx& rBitmapEx,
const basegfx::B2DPoint& rTopLeft,
const basegfx::B2DVector& rSize,
bool bTiling)
- : mpFillBitmapAttribute(new ImpFillBitmapAttribute(
+ : mpFillBitmapAttribute(ImpFillBitmapAttribute(
rBitmapEx, rTopLeft, rSize, bTiling))
{
}
@@ -100,59 +91,26 @@
FillBitmapAttribute::FillBitmapAttribute(const FillBitmapAttribute& rCandidate)
: mpFillBitmapAttribute(rCandidate.mpFillBitmapAttribute)
{
- mpFillBitmapAttribute->mnRefCount++;
}
FillBitmapAttribute::~FillBitmapAttribute()
{
- if(mpFillBitmapAttribute->mnRefCount)
- {
- mpFillBitmapAttribute->mnRefCount--;
- }
- else
- {
- delete mpFillBitmapAttribute;
- }
}
bool FillBitmapAttribute::isDefault() const
{
- return mpFillBitmapAttribute == ImpFillBitmapAttribute::get_global_default();
+ return mpFillBitmapAttribute.same_object(theGlobalDefault::get());
}
FillBitmapAttribute& FillBitmapAttribute::operator=(const FillBitmapAttribute& rCandidate)
{
- if(rCandidate.mpFillBitmapAttribute != mpFillBitmapAttribute)
- {
- if(mpFillBitmapAttribute->mnRefCount)
- {
- mpFillBitmapAttribute->mnRefCount--;
- }
- else
- {
- delete mpFillBitmapAttribute;
- }
-
- mpFillBitmapAttribute = rCandidate.mpFillBitmapAttribute;
- mpFillBitmapAttribute->mnRefCount++;
- }
-
+ mpFillBitmapAttribute = rCandidate.mpFillBitmapAttribute;
return *this;
}
bool FillBitmapAttribute::operator==(const FillBitmapAttribute& rCandidate) const
{
- if(rCandidate.mpFillBitmapAttribute == mpFillBitmapAttribute)
- {
- return true;
- }
-
- if(rCandidate.isDefault() != isDefault())
- {
- return false;
- }
-
- return (*rCandidate.mpFillBitmapAttribute == *mpFillBitmapAttribute);
+ return rCandidate.mpFillBitmapAttribute == mpFillBitmapAttribute;
}
const BitmapEx& FillBitmapAttribute::getBitmapEx() const
--
To view, visit https://gerrit.libreoffice.org/2948
To unsubscribe, visit https://gerrit.libreoffice.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0f666d4baaf6dc4e9f7ea30a518a8904f01d749f
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Thomas Arnhold <thomas at arnhold.org>
More information about the LibreOffice
mailing list