sc/inc/userlist.hxx | 37 ++++++------- sc/qa/unit/copy_paste_test.cxx | 3 - sc/source/core/tool/appoptio.cxx | 3 - sc/source/core/tool/userlist.cxx | 80 +++++------------------------- sc/source/filter/oox/autofilterbuffer.cxx | 2 sc/source/ui/optdlg/tpusrlst.cxx | 8 --- sc/source/ui/unoobj/appluno.cxx | 3 - 7 files changed, 38 insertions(+), 98 deletions(-)
New commits: commit 1fa085f223761b8dcd7e7ac592eb70450a774543 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sun Jun 4 12:48:50 2023 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sun Jun 4 14:13:24 2023 +0200 Simplify ScUserList, don't use unique_ptr. Change-Id: Idd0ce7bfff115a3b762e963dd6cea7927c78e295 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152586 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sc/inc/userlist.hxx b/sc/inc/userlist.hxx index e91fbcc0164e..7625ad15f5ee 100644 --- a/sc/inc/userlist.hxx +++ b/sc/inc/userlist.hxx @@ -23,13 +23,12 @@ #include <rtl/ustring.hxx> -#include <memory> #include <vector> /** * Stores individual user-defined sort list. */ -class SC_DLLPUBLIC ScUserListData +class SC_DLLPUBLIC ScUserListData final { public: struct SAL_DLLPRIVATE SubStr @@ -48,8 +47,9 @@ private: public: ScUserListData(OUString aStr); + // Copy ctor and assignment operator re-initialize tokens. Is this intended on copy? ScUserListData(const ScUserListData& rData); - ~ScUserListData(); + ScUserListData& operator=(const ScUserListData& rData); const OUString& GetString() const { return aStr; } void SetString(const OUString& rStr); @@ -65,32 +65,31 @@ public: */ class SC_DLLPUBLIC ScUserList { - typedef std::vector<std::unique_ptr<ScUserListData>> DataType; + typedef std::vector<ScUserListData> DataType; DataType maData; public: - typedef DataType::iterator iterator; - typedef DataType::const_iterator const_iterator; - ScUserList(); - ScUserList(const ScUserList& r); + ScUserList(const ScUserList& r) = default; + + void EraseData(size_t nIndex) { maData.erase(maData.cbegin() + nIndex); } const ScUserListData* GetData(const OUString& rSubStr) const; /// If the list in rStr is already inserted bool HasEntry(std::u16string_view rStr) const; - const ScUserListData& operator[](size_t nIndex) const; - ScUserListData& operator[](size_t nIndex); - ScUserList& operator=(const ScUserList& r); + const ScUserListData& operator[](size_t nIndex) const { return maData[nIndex]; } + ScUserListData& operator[](size_t nIndex) { return maData[nIndex]; } + ScUserList& operator=(const ScUserList& r) = default; bool operator==(const ScUserList& r) const; - bool operator!=(const ScUserList& r) const; - - iterator begin(); - const_iterator begin() const; - void clear(); - size_t size() const; - void push_back(ScUserListData* p); - void erase(const iterator& itr); + bool operator!=(const ScUserList& r) const { return !operator==(r); } + + void clear() { maData.clear(); } + size_t size() const { return maData.size(); } + template <class... Args> void emplace_back(Args&&... args) + { + maData.emplace_back(std::forward<Args>(args)...); + } }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/unit/copy_paste_test.cxx b/sc/qa/unit/copy_paste_test.cxx index b91dee89dea2..879c01844ba3 100644 --- a/sc/qa/unit/copy_paste_test.cxx +++ b/sc/qa/unit/copy_paste_test.cxx @@ -613,8 +613,7 @@ void ScCopyPasteTest::tdf137205_autofillDatesInMergedCells() void ScCopyPasteTest::addToUserList(const OUString& rStr) { - ScUserListData* aListData = new ScUserListData(rStr); - ScGlobal::GetUserList()->push_back(aListData); + ScGlobal::GetUserList()->emplace_back(rStr); } void ScCopyPasteTest::tdf137653_137654_autofillUserlist() diff --git a/sc/source/core/tool/appoptio.cxx b/sc/source/core/tool/appoptio.cxx index 3b19fbed2204..16a0c4cb9174 100644 --- a/sc/source/core/tool/appoptio.cxx +++ b/sc/source/core/tool/appoptio.cxx @@ -419,8 +419,7 @@ void ScAppCfg::ReadSortListCfg() for (const OUString& rStr : std::as_const(aSeq)) { - ScUserListData* pNew = new ScUserListData(rStr); - aList.push_back(pNew); + aList.emplace_back(rStr); } } diff --git a/sc/source/core/tool/userlist.cxx b/sc/source/core/tool/userlist.cxx index 6e0a4647a094..4540ad3ea0f6 100644 --- a/sc/source/core/tool/userlist.cxx +++ b/sc/source/core/tool/userlist.cxx @@ -97,8 +97,10 @@ ScUserListData::ScUserListData(const ScUserListData& rData) : InitTokens(); } -ScUserListData::~ScUserListData() +ScUserListData& ScUserListData::operator=(const ScUserListData& rData) { + SetString(rData.aStr); + return *this; } void ScUserListData::SetString( const OUString& rStr ) @@ -237,9 +239,9 @@ ScUserList::ScUserList() OUString aDayLong = aDayLongBuf.makeStringAndClear(); if ( !HasEntry( aDayShort ) ) - maData.push_back( std::make_unique<ScUserListData>( aDayShort )); + emplace_back(aDayShort); if ( !HasEntry( aDayLong ) ) - maData.push_back( std::make_unique<ScUserListData>( aDayLong )); + emplace_back(aDayLong); } xCal = rCalendar.Months; @@ -262,19 +264,13 @@ ScUserList::ScUserList() OUString aMonthLong = aMonthLongBuf.makeStringAndClear(); if ( !HasEntry( aMonthShort ) ) - maData.push_back( std::make_unique<ScUserListData>( aMonthShort )); + emplace_back(aMonthShort); if ( !HasEntry( aMonthLong ) ) - maData.push_back( std::make_unique<ScUserListData>( aMonthLong )); + emplace_back(aMonthLong); } } } -ScUserList::ScUserList(const ScUserList& rOther) -{ - for (const std::unique_ptr<ScUserListData>& rData : rOther.maData) - maData.push_back(std::make_unique<ScUserListData>(*rData)); -} - const ScUserListData* ScUserList::GetData(const OUString& rSubStr) const { const ScUserListData* pFirstCaseInsensitive = nullptr; @@ -283,79 +279,31 @@ const ScUserListData* ScUserList::GetData(const OUString& rSubStr) const for (const auto& rxItem : maData) { - if (rxItem->GetSubIndex(rSubStr, nIndex, bMatchCase)) + if (rxItem.GetSubIndex(rSubStr, nIndex, bMatchCase)) { if (bMatchCase) - return rxItem.get(); + return &rxItem; if (!pFirstCaseInsensitive) - pFirstCaseInsensitive = rxItem.get(); + pFirstCaseInsensitive = &rxItem; } } return pFirstCaseInsensitive; } -const ScUserListData& ScUserList::operator[](size_t nIndex) const -{ - return *maData[nIndex]; -} - -ScUserListData& ScUserList::operator[](size_t nIndex) -{ - return *maData[nIndex]; -} - -ScUserList& ScUserList::operator=( const ScUserList& rOther ) -{ - maData.clear(); - for (const std::unique_ptr<ScUserListData>& rData : rOther.maData) - maData.push_back(std::make_unique<ScUserListData>(*rData)); - return *this; -} - bool ScUserList::operator==( const ScUserList& r ) const { return std::equal(maData.begin(), maData.end(), r.maData.begin(), r.maData.end(), - [](const std::unique_ptr<ScUserListData>& lhs, const std::unique_ptr<ScUserListData>& rhs) { - return (lhs->GetString() == rhs->GetString()) && (lhs->GetSubCount() == rhs->GetSubCount()); + [](const ScUserListData& lhs, const ScUserListData& rhs) { + return (lhs.GetString() == rhs.GetString()) && (lhs.GetSubCount() == rhs.GetSubCount()); }); } -bool ScUserList::operator!=( const ScUserList& r ) const -{ - return !operator==( r ); -} - bool ScUserList::HasEntry( std::u16string_view rStr ) const { return ::std::any_of(maData.begin(), maData.end(), - [&] (std::unique_ptr<ScUserListData> const& pData) - { return pData->GetString() == rStr; } ); -} - -ScUserList::iterator ScUserList::begin() -{ - return maData.begin(); -} - -void ScUserList::clear() -{ - maData.clear(); -} - -size_t ScUserList::size() const -{ - return maData.size(); -} - -void ScUserList::push_back(ScUserListData* p) -{ - maData.push_back(std::unique_ptr<ScUserListData>(p)); -} - -void ScUserList::erase(const iterator& itr) -{ - maData.erase(itr); + [&] (ScUserListData const& pData) + { return pData.GetString() == rStr; } ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/oox/autofilterbuffer.cxx b/sc/source/filter/oox/autofilterbuffer.cxx index 9fa6de21d46b..ca0f031923a9 100644 --- a/sc/source/filter/oox/autofilterbuffer.cxx +++ b/sc/source/filter/oox/autofilterbuffer.cxx @@ -837,7 +837,7 @@ void AutoFilter::finalizeImport( const Reference< XDatabaseRange >& rxDatabaseRa if (!aParam.bUserDef) { - pUserList->push_back(new ScUserListData(rSorConditionLoaded.maSortCustomList)); + pUserList->emplace_back(rSorConditionLoaded.maSortCustomList); aParam.bUserDef = true; aParam.nUserIndex = pUserList->size()-1; } diff --git a/sc/source/ui/optdlg/tpusrlst.cxx b/sc/source/ui/optdlg/tpusrlst.cxx index 6553d64de926..cb3c6b5558bf 100644 --- a/sc/source/ui/optdlg/tpusrlst.cxx +++ b/sc/source/ui/optdlg/tpusrlst.cxx @@ -321,7 +321,7 @@ void ScTpUserLists::AddNewList( const OUString& rEntriesStr ) MakeListStr( theEntriesStr ); - pUserLists->push_back(new ScUserListData(theEntriesStr)); + pUserLists->emplace_back(theEntriesStr); } void ScTpUserLists::CopyListFromArea( const ScRefAddress& rStartPos, @@ -425,11 +425,7 @@ void ScTpUserLists::ModifyList( size_t nSelList, void ScTpUserLists::RemoveList( size_t nList ) { if (pUserLists && nList < pUserLists->size()) - { - ScUserList::iterator itr = pUserLists->begin(); - ::std::advance(itr, nList); - pUserLists->erase(itr); - } + pUserLists->EraseData(nList); } // Handler: diff --git a/sc/source/ui/unoobj/appluno.cxx b/sc/source/ui/unoobj/appluno.cxx index b7de3c764dda..9cfa82e4afc7 100644 --- a/sc/source/ui/unoobj/appluno.cxx +++ b/sc/source/ui/unoobj/appluno.cxx @@ -258,8 +258,7 @@ void SAL_CALL ScSpreadsheetSettings::setPropertyValue( pUserList->clear(); for (const OUString& aEntry : std::as_const(aSeq)) { - ScUserListData* pData = new ScUserListData(aEntry); - pUserList->push_back(pData); + pUserList->emplace_back(aEntry); } bSaveApp = true; // List with App-Options are saved }