[Libreoffice-commits] core.git: Branch 'feature/item_refactor2' - include/item item/source item/test
Armin Le Grand (via logerrit)
logerrit at kemper.freedesktop.org
Tue May 14 08:22:25 UTC 2019
include/item/simple/CntInt16.hxx | 2 -
include/item/simple/CntOUString.hxx | 38 +++++++++++++++++++-----
item/source/simple/CntOUString.cxx | 56 ++++++++++++++++++++++++++++++++----
item/test/ItemTest.cxx | 12 +++++++
4 files changed, 94 insertions(+), 14 deletions(-)
New commits:
commit 61e538cd9c5c04f9311fe6f67203adbdde00a7aa
Author: Armin Le Grand <Armin.Le.Grand at me.com>
AuthorDate: Tue May 14 10:18:53 2019 +0200
Commit: Armin Le Grand <Armin.Le.Grand at me.com>
CommitDate: Tue May 14 10:18:53 2019 +0200
WIP: Change Item class for rtl::OUString to shared
Checked in debugger if nowadays rtl::OUString is shared
at runtime office-wide, but that is not the case. Thus
adapted the basic Item:: class for all rtl::OUString
based Itens to use ItemBuffered and to share the instances
of strings. That will in the future be office-wide during
runtime and for all derived classes
Change-Id: Iaebadc9f15edc94c5f156721b0defce15fbc2713
diff --git a/include/item/simple/CntInt16.hxx b/include/item/simple/CntInt16.hxx
index a1bd7b51c91a..164e2afe85d9 100644
--- a/include/item/simple/CntInt16.hxx
+++ b/include/item/simple/CntInt16.hxx
@@ -36,7 +36,7 @@ namespace Item
virtual bool operator==(const ItemBase&) const;
sal_Int16 getValue() const { return m_nValue; }
- void putValue(sal_Int16 nNew) { m_nValue = nNew; }
+ void setValue(sal_Int16 nNew) { m_nValue = nNew; }
virtual bool getPresentation(
SfxItemPresentation,
diff --git a/include/item/simple/CntOUString.hxx b/include/item/simple/CntOUString.hxx
index 9f72ee5e25f6..87cea1749d34 100644
--- a/include/item/simple/CntOUString.hxx
+++ b/include/item/simple/CntOUString.hxx
@@ -10,7 +10,7 @@
#ifndef INCLUDED_ITEM_SIMPLE_CNTOUSTRING_HXX
#define INCLUDED_ITEM_SIMPLE_CNTOUSTRING_HXX
-#include <item/base/ItemBase.hxx>
+#include <item/base/ItemBuffered.hxx>
#include <rtl/ustring.hxx>
///////////////////////////////////////////////////////////////////////////////
@@ -21,11 +21,33 @@ namespace Item
// this is a helper base class, so it has *no* method
// static ItemControlBlock& GetStaticItemControlBlock();
// and also no public constructor (!), but implements all the
- // tooling methods for Items using a sal_Int16 internally
- class ITEM_DLLPUBLIC CntOUString : public ItemBase
+ // tooling methods for Items using a sal_Int16 internally.
+ // I checked if rtl::OUString nowadays already does some
+ // office-wide runtime matching and buffering to hold the
+ // string data only once, but this is not the case. Construction
+ // is optimized, but no shared data usage. Thus, use ItemBuffered
+ // as base class and implement shared ItemData for rtl::OUString
+ // here now to always only have one instance for CntOUString-based
+ // derivations. This will use ItemAdministrator_set, see *.cxx
+ // for details
+ class ITEM_DLLPUBLIC CntOUString : public ItemBuffered
{
- private:
- rtl::OUString m_aValue;
+ protected:
+ // ItemData class for ref-counted rtl::OUString instances
+ class CntOUString_Data : public ItemData
+ {
+ private:
+ rtl::OUString m_aValue;
+
+ protected:
+ virtual ItemAdministrator& getItemAdministrator() const override;
+
+ public:
+ CntOUString_Data(const rtl::OUString& rValue = rtl::OUString());
+ virtual bool operator==(const ItemData& rRef) const override;
+ const rtl::OUString& getValue() const { return m_aValue; }
+ void setValue(const rtl::OUString& rValue) { m_aValue = rValue; }
+ };
protected:
// constructor for derived classes that *have* to hand
@@ -34,10 +56,10 @@ namespace Item
public:
CntOUString() = delete;
- virtual bool operator==(const ItemBase&) const;
+ virtual bool operator==(const ItemBase&) const override;
- const rtl::OUString& getValue() const { return m_aValue; }
- void putValue(const rtl::OUString& rValue) { m_aValue = rValue; }
+ const rtl::OUString& getValue() const;
+ void setValue(const rtl::OUString& rValue);
virtual bool getPresentation(
SfxItemPresentation,
diff --git a/item/source/simple/CntOUString.cxx b/item/source/simple/CntOUString.cxx
index 08d91e618326..ba397337dc11 100644
--- a/item/source/simple/CntOUString.cxx
+++ b/item/source/simple/CntOUString.cxx
@@ -9,24 +9,70 @@
#include <item/simple/CntOUString.hxx>
#include <item/base/ItemControlBlock.hxx>
+#include <item/base/ItemAdministrator.hxx>
#include <cassert>
///////////////////////////////////////////////////////////////////////////////
namespace Item
{
- CntOUString::CntOUString(ItemControlBlock& rItemControlBlock, const rtl::OUString& rValue)
- : ItemBase(rItemControlBlock),
+ ItemAdministrator& CntOUString::CntOUString_Data::getItemAdministrator() const
+ {
+ static ItemAdministrator_set aItemAdministrator_set(
+ // hand over localized lambda call to construct a new instance of Item
+ []()
+ {
+ return new CntOUString_Data(rtl::OUString());
+ },
+ // hand over localized lambda call to clone an Item
+ [](const ItemData& rRef)
+ {
+ const CntOUString_Data& rData(static_cast<const CntOUString_Data&>(rRef));
+ return new CntOUString_Data(rData.getValue());
+ },
+ // hand over localized lambda operator< to have a sorted set
+ [](ItemData* A, ItemData* B)
+ {
+ return static_cast<CntOUString_Data*>(A)->getValue() < static_cast<CntOUString_Data*>(B)->getValue();
+ });
+
+ return aItemAdministrator_set;
+ }
+
+ CntOUString::CntOUString_Data::CntOUString_Data(const rtl::OUString& rValue)
+ : ItemData(),
m_aValue(rValue)
{
}
+ bool CntOUString::CntOUString_Data::operator==(const ItemData& rRef) const
+ {
+ return ItemData::operator==(rRef) || // ptr-compare
+ getValue() == static_cast<const CntOUString_Data&>(rRef).getValue(); // content compare
+ }
+
+ CntOUString::CntOUString(ItemControlBlock& rItemControlBlock, const rtl::OUString& rValue)
+ : ItemBuffered(rItemControlBlock)
+ {
+ setItemData(new CntOUString_Data(rValue));
+ }
+
bool CntOUString::operator==(const ItemBase& rRef) const
{
return ItemBase::operator==(rRef) || // ptr-compare
getValue() == static_cast<const CntOUString&>(rRef).getValue();
}
+ const rtl::OUString& CntOUString::getValue() const
+ {
+ return static_cast<CntOUString_Data&>(getItemData()).getValue();
+ }
+
+ void CntOUString::setValue(const rtl::OUString& rValue)
+ {
+ setItemData(new CntOUString_Data(rValue));
+ }
+
bool CntOUString::getPresentation(
SfxItemPresentation,
MapUnit,
@@ -34,13 +80,13 @@ namespace Item
rtl::OUString& rText,
const IntlWrapper&) const
{
- rText = m_aValue;
+ rText = getValue();
return true;
}
bool CntOUString::queryValue(css::uno::Any& rVal, sal_uInt8) const
{
- rVal <<= m_aValue;
+ rVal <<= getValue();
return true;
}
@@ -50,7 +96,7 @@ namespace Item
if(rVal >>= aTheValue)
{
- m_aValue = aTheValue;
+ setValue(aTheValue);
return true;
}
diff --git a/item/test/ItemTest.cxx b/item/test/ItemTest.cxx
index 705867a81d04..1347bd775ddb 100644
--- a/item/test/ItemTest.cxx
+++ b/item/test/ItemTest.cxx
@@ -1434,6 +1434,13 @@ namespace Item
void checkSimpleItems()
{
+ // for debug, change bLoop to true, start, attach and set to false again to debug (one possibility...)
+ static bool bLoop(false);
+ while(bLoop)
+ {
+ bLoop = true;
+ }
+
static bool bInit(false);
static CntInt16_derived a_sp, b_sp, c_sp;
static CntInt16_derived theDefault;
@@ -1490,6 +1497,11 @@ namespace Item
CntOUString_derived shas3(CntOUString_derived("Hello"));
CntOUString_derived shas4(CntOUString_derived("WhateverComesAlong"));
+ CntOUString_derived shas5(CntOUString_derived("RgnfShoe2474"));
+ CntOUString_derived shas6(CntOUString_derived("RgnfShoe2474"));
+ CntOUString_derived shas7(CntOUString_derived("RgnfShoe2474"));
+ CntOUString_derived shas8(CntOUString_derived("RgnfShoe2474"));
+
if(CntOUString_derived("NotDefault").isDefault())
{
nIncrement++;
More information about the Libreoffice-commits
mailing list