[Libreoffice-commits] core.git: 2 commits - sc/inc sc/source sd/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Thu Oct 4 06:16:03 UTC 2018
sc/inc/dptabres.hxx | 13 +++----------
sc/source/core/data/column.cxx | 19 +++++--------------
sc/source/core/data/column4.cxx | 1 +
sc/source/core/data/dptabres.cxx | 22 ++++++++++------------
sd/source/filter/eppt/pptx-text.cxx | 15 ++++-----------
5 files changed, 23 insertions(+), 47 deletions(-)
New commits:
commit 96a032743339f315ffff13fd8dc9191acffcc636
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Oct 3 15:23:13 2018 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Oct 4 08:15:48 2018 +0200
reserve space before appending to vector in a loop
Change-Id: Ib0017fc2a57ab90596aa494934c9579cae4bf4aa
Reviewed-on: https://gerrit.libreoffice.org/61301
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index a63cc1193254..2617a72b115b 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -3345,11 +3345,10 @@ namespace {
class TransferListenersHandler
{
public:
- typedef std::vector<SvtListener*> ListenersType;
struct Entry
{
size_t mnRow;
- ListenersType maListeners;
+ std::vector<SvtListener*> maListeners;
};
typedef std::vector<Entry> ListenerListType;
@@ -3362,22 +3361,14 @@ public:
{
assert(pBroadcaster);
- // It's important to make a copy here.
- SvtBroadcaster::ListenersType aLis = pBroadcaster->GetAllListeners();
- if (aLis.empty())
+ // It's important to make a copy of the broadcasters listener list here
+ Entry aEntry { nRow, pBroadcaster->GetAllListeners() };
+ if (aEntry.maListeners.empty())
// No listeners to transfer.
return;
- Entry aEntry;
- aEntry.mnRow = nRow;
-
- SvtBroadcaster::ListenersType::iterator it = aLis.begin(), itEnd = aLis.end();
- for (; it != itEnd; ++it)
- {
- SvtListener* pLis = *it;
+ for (SvtListener* pLis : aEntry.maListeners)
pLis->EndListening(*pBroadcaster);
- aEntry.maListeners.push_back(pLis);
- }
maListenerList.push_back(aEntry);
diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx
index 608cef4609e2..3fac1ea00947 100644
--- a/sc/source/core/data/column4.cxx
+++ b/sc/source/core/data/column4.cxx
@@ -1226,6 +1226,7 @@ public:
void operator() ( size_t /*nRow*/, SvtBroadcaster* p )
{
SvtBroadcaster::ListenersType& rLis = p->GetAllListeners();
+ mrListeners.reserve(mrListeners.size() + rLis.size());
std::copy(rLis.begin(), rLis.end(), std::back_inserter(mrListeners));
}
};
commit 5c7de51f908e866cdab7dbf4aa22aa48f42dc153
Author: Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Oct 2 10:55:46 2018 +0200
Commit: Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Oct 4 08:15:37 2018 +0200
loplugin:useuniqueptr in ResultMembers
no need to store a small structure separately on the heap
Change-Id: I054ca078242225d12cf8abc86e25813586e6495f
Reviewed-on: https://gerrit.libreoffice.org/61299
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sc/inc/dptabres.hxx b/sc/inc/dptabres.hxx
index 276392fbe6be..990fbe8172e8 100644
--- a/sc/inc/dptabres.hxx
+++ b/sc/inc/dptabres.hxx
@@ -218,11 +218,6 @@ class ScDPDataMember;
#define SC_DPMEASURE_ALL -1
#define SC_DPMEASURE_ANY -2
-struct MemberHashIndexFunc
-{
- size_t operator() (SCROW rDataIndex) const { return rDataIndex; }
-};
-
struct ScDPParentDimData
{
const SCROW mnOrder; //! Ref
@@ -234,15 +229,13 @@ struct ScDPParentDimData
ScDPParentDimData(SCROW nIndex, const ScDPDimension* pDim, const ScDPLevel* pLev, const ScDPMember* pMember);
};
-typedef std::unordered_map < SCROW, ScDPParentDimData *, MemberHashIndexFunc> DimMemberHash;
-
class ResultMembers final
{
- DimMemberHash maMemberHash;
+ std::unordered_map<SCROW, ScDPParentDimData> maMemberHash;
bool mbHasHideDetailsMember;
public:
- ScDPParentDimData* FindMember( SCROW nIndex ) const;
- void InsertMember( ScDPParentDimData* pNew );
+ const ScDPParentDimData* FindMember( SCROW nIndex ) const;
+ void InsertMember( ScDPParentDimData const & rNew );
bool IsHasHideDetailsMembers() const { return mbHasHideDetailsMember; }
void SetHasHideDetailsMembers( bool b ) { mbHasHideDetailsMember = b; }
ResultMembers();
diff --git a/sc/source/core/data/dptabres.cxx b/sc/source/core/data/dptabres.cxx
index e5bef46c3256..7b9e9aa9c792 100644
--- a/sc/source/core/data/dptabres.cxx
+++ b/sc/source/core/data/dptabres.cxx
@@ -929,8 +929,8 @@ ResultMembers& ScDPResultData::GetDimResultMembers(long nDim, const ScDPDimensio
ScDPMember* pMember = pMembers->getByIndex(nSorted);
if (!pResultMembers->FindMember(pMember->GetItemDataId()))
{
- ScDPParentDimData* pNew = new ScDPParentDimData(i, pDim, pLevel, pMember);
- pResultMembers->InsertMember(pNew);
+ ScDPParentDimData aNew(i, pDim, pLevel, pMember);
+ pResultMembers->InsertMember(aNew);
}
}
@@ -4021,7 +4021,7 @@ void ScDPResultDimension::InitWithMembers(
if ( pResultMember == nullptr )
{ //only insert found item
- ScDPParentDimData* pMemberData = rMembers.FindMember( nDataID );
+ const ScDPParentDimData* pMemberData = rMembers.FindMember( nDataID );
if ( pMemberData && aCompare.IsIncluded( *( pMemberData->mpMemberDesc ) ) )
pResultMember = InsertMember( pMemberData );
}
@@ -4041,20 +4041,20 @@ ScDPParentDimData::ScDPParentDimData(
SCROW nIndex, const ScDPDimension* pDim, const ScDPLevel* pLev, const ScDPMember* pMember) :
mnOrder(nIndex), mpParentDim(pDim), mpParentLevel(pLev), mpMemberDesc(pMember) {}
-ScDPParentDimData* ResultMembers::FindMember( SCROW nIndex ) const
+const ScDPParentDimData* ResultMembers::FindMember( SCROW nIndex ) const
{
- DimMemberHash::const_iterator aRes = maMemberHash.find( nIndex );
+ auto aRes = maMemberHash.find( nIndex );
if( aRes != maMemberHash.end()) {
- if ( aRes->second->mpMemberDesc && aRes->second->mpMemberDesc->GetItemDataId()==nIndex )
- return aRes->second;
+ if ( aRes->second.mpMemberDesc && aRes->second.mpMemberDesc->GetItemDataId()==nIndex )
+ return &aRes->second;
}
return nullptr;
}
-void ResultMembers::InsertMember( ScDPParentDimData* pNew )
+void ResultMembers::InsertMember( const ScDPParentDimData& rNew )
{
- if ( !pNew->mpMemberDesc->getShowDetails() )
+ if ( !rNew.mpMemberDesc->getShowDetails() )
mbHasHideDetailsMember = true;
- maMemberHash.insert( std::pair< const SCROW, ScDPParentDimData *>( pNew->mpMemberDesc->GetItemDataId(), pNew ) );
+ maMemberHash.emplace( rNew.mpMemberDesc->GetItemDataId(), rNew );
}
ResultMembers::ResultMembers():
@@ -4063,8 +4063,6 @@ ResultMembers::ResultMembers():
}
ResultMembers::~ResultMembers()
{
- for ( DimMemberHash::const_iterator iter = maMemberHash.begin(); iter != maMemberHash.end(); ++iter )
- delete iter->second;
}
LateInitParams::LateInitParams(
diff --git a/sd/source/filter/eppt/pptx-text.cxx b/sd/source/filter/eppt/pptx-text.cxx
index bbcc1a1a7312..71d05d0910cd 100644
--- a/sd/source/filter/eppt/pptx-text.cxx
+++ b/sd/source/filter/eppt/pptx-text.cxx
@@ -1267,11 +1267,10 @@ struct ImplTextObj
{
sal_uInt32 mnTextSize;
int mnInstance;
- std::vector<ParagraphObj*> maList;
+ std::vector<std::unique_ptr<ParagraphObj>> maList;
bool mbHasExtendedBullets;
explicit ImplTextObj( int nInstance );
- ~ImplTextObj();
};
ImplTextObj::ImplTextObj( int nInstance )
@@ -1282,12 +1281,6 @@ ImplTextObj::ImplTextObj( int nInstance )
mbHasExtendedBullets = false;
}
-ImplTextObj::~ImplTextObj()
-{
- for ( std::vector<ParagraphObj*>::const_iterator it = maList.begin(); it != maList.end(); ++it )
- delete *it;
-}
-
TextObj::TextObj( css::uno::Reference< css::text::XSimpleText > const & rXTextRef,
int nInstance, FontCollection& rFontCollection, PPTExBulletProvider& rProv ):
mpImplTextObj(new ImplTextObj(nInstance))
@@ -1308,9 +1301,9 @@ TextObj::TextObj( css::uno::Reference< css::text::XSimpleText > const & rXTextRe
{
if ( !aXTextParagraphE->hasMoreElements() )
aParaFlags.bLastParagraph = true;
- ParagraphObj* pPara = new ParagraphObj( aXParagraph, aParaFlags, rFontCollection, rProv );
+ std::unique_ptr<ParagraphObj> pPara(new ParagraphObj( aXParagraph, aParaFlags, rFontCollection, rProv ));
mpImplTextObj->mbHasExtendedBullets |= pPara->bExtendedBulletsUsed;
- mpImplTextObj->maList.push_back( pPara );
+ mpImplTextObj->maList.push_back( std::move(pPara) );
aParaFlags.bFirstParagraph = false;
}
}
@@ -1328,7 +1321,7 @@ void TextObj::ImplCalculateTextPositions()
ParagraphObj* TextObj::GetParagraph(int idx)
{
- return mpImplTextObj->maList[idx];
+ return mpImplTextObj->maList[idx].get();
}
sal_uInt32 TextObj::ParagraphCount() const
More information about the Libreoffice-commits
mailing list