sc/inc/userlist.hxx | 7 +++--- sc/source/core/tool/appoptio.cxx | 4 +-- sc/source/core/tool/userlist.cxx | 45 ++++++++++++++++++++++++++------------- sc/source/ui/optdlg/tpusrlst.cxx | 2 - sc/source/ui/unoobj/appluno.cxx | 4 +-- 5 files changed, 39 insertions(+), 23 deletions(-)
New commits: commit 0bcef149ce3785306271fa06184eb62950b62087 Author: Noel Grandin <n...@peralex.com> Date: Fri Dec 11 14:57:10 2015 +0200 tdf#96339 fix bug in sort list this bug was caused by commit 2aacf6c2cd82322b953988ff30d3bc997ae76d7b "sc: boost::ptr_vector->std::vector" Since the code in question likes passing around a pointer to the element of the vector, convert to using std::vector<std::unique_ptr> Change-Id: I9e9676fe7c2dc32e23ba6708aaea1f16c1bf2ff8 diff --git a/sc/inc/userlist.hxx b/sc/inc/userlist.hxx index 1933b84..b103aee 100644 --- a/sc/inc/userlist.hxx +++ b/sc/inc/userlist.hxx @@ -22,6 +22,7 @@ #include "scdllapi.h" +#include <memory> #include <vector> /** @@ -46,6 +47,7 @@ private: public: ScUserListData(const OUString& rStr); ScUserListData(const ScUserListData& rData); + ~ScUserListData(); const OUString& GetString() const { return aStr; } void SetString(const OUString& rStr); @@ -61,7 +63,7 @@ public: */ class SC_DLLPUBLIC ScUserList { - typedef std::vector<ScUserListData> DataType; + typedef std::vector< std::unique_ptr<ScUserListData> > DataType; DataType maData; public: typedef DataType::iterator iterator; @@ -83,9 +85,8 @@ public: iterator begin(); const_iterator begin() const; void clear(); - void reserve(size_t nSize) { maData.reserve(nSize); } size_t size() const; - void push_back(const ScUserListData& r) { maData.push_back(r); } + void push_back(ScUserListData* p); void erase(iterator itr); }; diff --git a/sc/source/core/tool/appoptio.cxx b/sc/source/core/tool/appoptio.cxx index 5328f67..3bdf429 100644 --- a/sc/source/core/tool/appoptio.cxx +++ b/sc/source/core/tool/appoptio.cxx @@ -180,11 +180,11 @@ static void lcl_SetSortList( const Any& rValue ) if (!bDefault) { aList.clear(); - aList.reserve(nCount); for (long i=0; i<nCount; i++) { - aList.push_back( ScUserListData( pArray[i] ) ); + ScUserListData* pNew = new ScUserListData( pArray[i] ); + aList.push_back(pNew); } } diff --git a/sc/source/core/tool/userlist.cxx b/sc/source/core/tool/userlist.cxx index 0299bfe..39344a9 100644 --- a/sc/source/core/tool/userlist.cxx +++ b/sc/source/core/tool/userlist.cxx @@ -24,6 +24,7 @@ #include <unotools/localedatawrapper.hxx> #include <unotools/calendarwrapper.hxx> #include <unotools/transliterationwrapper.hxx> +#include <o3tl/make_unique.hxx> #include <boost/bind.hpp> #include <algorithm> @@ -96,6 +97,10 @@ ScUserListData::ScUserListData(const ScUserListData& rData) : InitTokens(); } +ScUserListData::~ScUserListData() +{ +} + void ScUserListData::SetString( const OUString& rStr ) { aStr = rStr; @@ -233,9 +238,9 @@ ScUserList::ScUserList() OUString aDayLong = aDayLongBuf.makeStringAndClear(); if ( !HasEntry( aDayShort ) ) - maData.push_back( ScUserListData( aDayShort )); + maData.push_back( o3tl::make_unique<ScUserListData>( aDayShort )); if ( !HasEntry( aDayLong ) ) - maData.push_back( ScUserListData( aDayLong )); + maData.push_back( o3tl::make_unique<ScUserListData>( aDayLong )); } xCal = xCalendars[j].Months; @@ -258,15 +263,18 @@ ScUserList::ScUserList() OUString aMonthLong = aMonthLongBuf.makeStringAndClear(); if ( !HasEntry( aMonthShort ) ) - maData.push_back( ScUserListData( aMonthShort )); + maData.push_back( o3tl::make_unique<ScUserListData>( aMonthShort )); if ( !HasEntry( aMonthLong ) ) - maData.push_back( ScUserListData( aMonthLong )); + maData.push_back( o3tl::make_unique<ScUserListData>( aMonthLong )); } } } -ScUserList::ScUserList(const ScUserList& r) : - maData(r.maData) {} +ScUserList::ScUserList(const ScUserList& rOther) +{ + for (const std::unique_ptr<ScUserListData>& rData : rOther.maData) + maData.push_back( o3tl::make_unique<ScUserListData>(*rData.get()) ); +} const ScUserListData* ScUserList::GetData(const OUString& rSubStr) const { @@ -277,12 +285,12 @@ const ScUserListData* ScUserList::GetData(const OUString& rSubStr) const for (; itr != itrEnd; ++itr) { - if (itr->GetSubIndex(rSubStr, nIndex, bMatchCase)) + if ((*itr)->GetSubIndex(rSubStr, nIndex, bMatchCase)) { if (bMatchCase) - return &(*itr); + return itr->get(); if (!pFirstCaseInsensitive) - pFirstCaseInsensitive = &(*itr); + pFirstCaseInsensitive = itr->get(); } } @@ -291,17 +299,19 @@ const ScUserListData* ScUserList::GetData(const OUString& rSubStr) const const ScUserListData& ScUserList::operator[](size_t nIndex) const { - return maData[nIndex]; + return *maData[nIndex].get(); } ScUserListData& ScUserList::operator[](size_t nIndex) { - return maData[nIndex]; + return *maData[nIndex].get(); } -ScUserList& ScUserList::operator=( const ScUserList& r ) +ScUserList& ScUserList::operator=( const ScUserList& rOther ) { - maData = r.maData; + maData.clear(); + for (const std::unique_ptr<ScUserListData>& rData : rOther.maData) + maData.push_back( o3tl::make_unique<ScUserListData>(*rData.get()) ); return *this; } @@ -313,8 +323,8 @@ bool ScUserList::operator==( const ScUserList& r ) const DataType::const_iterator itr1 = maData.begin(), itr2 = r.maData.begin(), itrEnd = maData.end(); for (; itr1 != itrEnd; ++itr1, ++itr2) { - const ScUserListData& v1 = *itr1; - const ScUserListData& v2 = *itr2; + const ScUserListData& v1 = *itr1->get(); + const ScUserListData& v2 = *itr2->get(); if (v1.GetString() != v2.GetString() || v1.GetSubCount() != v2.GetSubCount()) return false; } @@ -346,6 +356,11 @@ 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(iterator itr) { maData.erase(itr); diff --git a/sc/source/ui/optdlg/tpusrlst.cxx b/sc/source/ui/optdlg/tpusrlst.cxx index 2511027..9a4ff48 100644 --- a/sc/source/ui/optdlg/tpusrlst.cxx +++ b/sc/source/ui/optdlg/tpusrlst.cxx @@ -344,7 +344,7 @@ void ScTpUserLists::AddNewList( const OUString& rEntriesStr ) MakeListStr( theEntriesStr ); - pUserLists->push_back(ScUserListData(rEntriesStr)); + pUserLists->push_back(new ScUserListData(theEntriesStr)); } void ScTpUserLists::CopyListFromArea( const ScRefAddress& rStartPos, diff --git a/sc/source/ui/unoobj/appluno.cxx b/sc/source/ui/unoobj/appluno.cxx index c1d847d..b597272 100644 --- a/sc/source/ui/unoobj/appluno.cxx +++ b/sc/source/ui/unoobj/appluno.cxx @@ -356,12 +356,12 @@ void SAL_CALL ScSpreadsheetSettings::setPropertyValue( pUserList->clear(); // alle Eintraege raus sal_uInt16 nCount = (sal_uInt16)aSeq.getLength(); - pUserList->reserve(nCount); const OUString* pAry = aSeq.getConstArray(); for (sal_uInt16 i=0; i<nCount; i++) { OUString aEntry = pAry[i]; - pUserList->push_back( ScUserListData(aEntry) ); + ScUserListData* pData = new ScUserListData(aEntry); + pUserList->push_back(pData); } bSaveApp = true; // Liste wird mit den App-Optionen gespeichert } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits