[Libreoffice-commits] core.git: Branch 'feature/item_refactor2' - include/item item/source item/test
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 AuthorDate: Tue May 14 10:18:53 2019 +0200 Commit: Armin Le Grand 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 +#include #include /// @@ -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 #include +#include #include /// 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 +[]() +{
[Libreoffice-commits] core.git: Branch 'feature/item_refactor2' - include/item item/source
include/item/base/ItemAdministrator.hxx |2 +- include/item/base/ItemBase.hxx |6 -- include/item/base/ItemBuffered.hxx |8 +--- include/item/base/ItemControlBlock.hxx |5 +++-- item/source/base/ItemBase.cxx | 11 +++ item/source/base/ItemBuffered.cxx | 19 ++- item/source/base/ItemControlBlock.cxx |2 +- 7 files changed, 31 insertions(+), 22 deletions(-) New commits: commit 4b0409c319abd3248360345cf7d86d66b932d513 Author: Armin Le Grand AuthorDate: Mon May 6 15:45:26 2019 +0200 Commit: Armin Le Grand CommitDate: Mon May 6 15:45:26 2019 +0200 WIP: Linux build changes Change-Id: I3ea79f9a48f626681604e871143c0adec7c0cb7a diff --git a/include/item/base/ItemAdministrator.hxx b/include/item/base/ItemAdministrator.hxx index 4b77f5ffafca..18a3a6eb953a 100644 --- a/include/item/base/ItemAdministrator.hxx +++ b/include/item/base/ItemAdministrator.hxx @@ -31,7 +31,7 @@ namespace Item { -class ItemAdministrator +class ITEM_DLLPUBLIC ItemAdministrator { private: std::functionm_aConstructItem; diff --git a/include/item/base/ItemBase.hxx b/include/item/base/ItemBase.hxx index 44c597cddbed..b93d5b196ce9 100644 --- a/include/item/base/ItemBase.hxx +++ b/include/item/base/ItemBase.hxx @@ -42,7 +42,7 @@ namespace Item // PutValue/Any interface for automated instance creation from SfxType // mechanism (UNO API and sfx2 stuff) -virtual void putValues(const AnyIDArgs& rArgs); +virtual void putAnyValues(const AnyIDArgs& rArgs); private: // local reference to instance of ItemControlBlock for this @@ -55,10 +55,12 @@ namespace Item protected: // PutValue/Any interface for automated instance creation from SfxType // mechanism (UNO API and sfx2 stuff) -virtual void putValue(const css::uno::Any& rVal, sal_uInt8 nMemberId); +virtual void putAnyValue(const css::uno::Any& rVal, sal_uInt8 nMemberId); public: ItemBase(ItemControlBlock& rItemControlBlock); +virtual ~ItemBase(); + ItemBase(const ItemBase&); ItemBase& operator=(const ItemBase&); diff --git a/include/item/base/ItemBuffered.hxx b/include/item/base/ItemBuffered.hxx index 82647198efaf..43727586ffbf 100755 --- a/include/item/base/ItemBuffered.hxx +++ b/include/item/base/ItemBuffered.hxx @@ -29,6 +29,8 @@ namespace Item { +class ItemAdministrator; + class ITEM_DLLPUBLIC ItemBuffered : public ItemBase { public: @@ -44,7 +46,7 @@ namespace Item // PutValue/Any interface for automated instance creation from SfxType // mechanism (UNO API and sfx2 stuff) -virtual void putValue(const css::uno::Any& rVal, sal_uInt8 nMemberId); +virtual void putAnyValue(const css::uno::Any& rVal, sal_uInt8 nMemberId); public: ItemData(); @@ -67,7 +69,7 @@ namespace Item public: // PutValue/Any interface for automated instance creation from SfxType // mechanism (UNO API and sfx2 stuff) -virtual void putValues(const AnyIDArgs& rArgs); +virtual void putAnyValues(const AnyIDArgs& rArgs); protected: // Method to internally (thus protected) set a new ItemData @@ -90,7 +92,7 @@ namespace Item virtual ~ItemBuffered(); ItemBuffered& operator=(const ItemBuffered&); -virtual bool operator==(const ItemBuffered&) const; +virtual bool operator==(const ItemBase&) const; virtual std::unique_ptr clone() const; }; } // end of namespace Item diff --git a/include/item/base/ItemControlBlock.hxx b/include/item/base/ItemControlBlock.hxx index b83f37333d29..80effd85a24a 100755 --- a/include/item/base/ItemControlBlock.hxx +++ b/include/item/base/ItemControlBlock.hxx @@ -22,15 +22,16 @@ #include #include +#include #include +#include +#include /// namespace Item { // predefine - no need to include -class ItemBase; - class ITEM_DLLPUBLIC ItemControlBlock { private: diff --git a/item/source/base/ItemBase.cxx b/item/source/base/ItemBase.cxx index 158972837d15..40be2aeb73f8 100644 --- a/item/source/base/ItemBase.cxx +++ b/item/source/base/ItemBase.cxx @@ -8,7 +8,6 @@ */ #include -// #include #include #include @@ -86,18 +85,18 @@ Nonetheless these SlotItems STILL depend on the SfxItem-RANGES defined in the Sf namespace Item { -void ItemBase::putValues(const AnyIDArgs& rArgs) +void ItemBase::putAnyValues(const AnyIDArgs& rArgs) { if(!rArgs.empty()) { for(const auto& arg : rArgs) { -putValue(arg.first, arg.second); +putAnyValue(arg.first, arg.second); } } } -void ItemBase::putValue(const