filter/source/msfilter/msdffimp.cxx | 21 ++++++++++++++------- include/filter/msfilter/msdffimp.hxx | 17 +++++++++++------ sw/source/filter/ww8/ww8graf.cxx | 5 ++--- sw/source/filter/ww8/ww8par.cxx | 2 +- 4 files changed, 28 insertions(+), 17 deletions(-)
New commits: commit 9887cd14e2777eed019aacfd0ac75554686c6b79 Author: Caolán McNamara <[email protected]> Date: Thu Apr 19 14:43:40 2018 +0100 use a map to avoid looping on every obj delete Change-Id: I47ff4f0f959b7d09fc91593b7dacb3d1a2b50472 Reviewed-on: https://gerrit.libreoffice.org/53164 Tested-by: Jenkins <[email protected]> Reviewed-by: Caolán McNamara <[email protected]> Tested-by: Caolán McNamara <[email protected]> diff --git a/filter/source/msfilter/msdffimp.cxx b/filter/source/msfilter/msdffimp.cxx index 6e1726c9785c..f2fbc026c16d 100644 --- a/filter/source/msfilter/msdffimp.cxx +++ b/filter/source/msfilter/msdffimp.cxx @@ -5030,14 +5030,18 @@ void SvxMSDffManager::GetGroupAnchors( const DffRecordHeader& rHd, SvStream& rSt SvxMSDffImportRec* SvxMSDffImportData::find(const SdrObject* pObj) { - for (const auto& it : *this) - { - if (it->pObj == pObj) - return it.get(); - } + auto it = m_ObjToRecMap.find(pObj); + if (it != m_ObjToRecMap.end()) + return it->second; return nullptr; } +void SvxMSDffImportData::insert(SvxMSDffImportRec* pImpRec) +{ + m_ObjToRecMap[pImpRec->pObj] = pImpRec; + m_Records.insert(std::unique_ptr<SvxMSDffImportRec>(pImpRec)); +} + void SvxMSDffManager::NotifyFreeObj(void* pData, SdrObject* pObj) { if (SdrObjGroup* pGroup = dynamic_cast<SdrObjGroup*>(pObj)) @@ -5050,7 +5054,10 @@ void SvxMSDffManager::NotifyFreeObj(void* pData, SdrObject* pObj) SvxMSDffImportData& rImportData = *static_cast<SvxMSDffImportData*>(pData); if (SvxMSDffImportRec* pRecord = rImportData.find(pObj)) + { + rImportData.unmap(pObj); pRecord->pObj = nullptr; + } } void SvxMSDffManager::FreeObj(void* pData, SdrObject* pObj) @@ -5543,7 +5550,7 @@ SdrObject* SvxMSDffManager::ProcessObj(SvStream& rSt, if( pOrgObj ) { pImpRec->pObj = pOrgObj; - rImportData.m_Records.insert(std::unique_ptr<SvxMSDffImportRec>(pImpRec)); + rImportData.insert(pImpRec); bDeleteImpRec = false; if (pImpRec == pTextImpRec) bDeleteTextImpRec = false; @@ -5554,7 +5561,7 @@ SdrObject* SvxMSDffManager::ProcessObj(SvStream& rSt, // Modify ShapeId (must be unique) pImpRec->nShapeId |= 0x8000000; pTextImpRec->pObj = pTextObj; - rImportData.m_Records.insert(std::unique_ptr<SvxMSDffImportRec>(pTextImpRec)); + rImportData.insert(pTextImpRec); bDeleteTextImpRec = false; if (pTextImpRec == pImpRec) bDeleteImpRec = false; diff --git a/include/filter/msfilter/msdffimp.hxx b/include/filter/msfilter/msdffimp.hxx index 022994a51873..5c0742a39f0a 100644 --- a/include/filter/msfilter/msdffimp.hxx +++ b/include/filter/msfilter/msdffimp.hxx @@ -262,16 +262,18 @@ private: SvxMSDffImportRec &operator=(const SvxMSDffImportRec&) = delete; }; -/** list of all SvxMSDffImportRec instances of/for a group */ -typedef std::set<std::unique_ptr<SvxMSDffImportRec>, - comphelper::UniquePtrValueLess<SvxMSDffImportRec>> MSDffImportRecords; - /** block of parameters for import/export for a single call of ImportObjAtCurrentStreamPos() */ -struct MSFILTER_DLLPUBLIC SvxMSDffImportData +class MSFILTER_DLLPUBLIC SvxMSDffImportData { +private: + /** list of all SvxMSDffImportRec instances of/for a group */ + typedef std::set<std::unique_ptr<SvxMSDffImportRec>, + comphelper::UniquePtrValueLess<SvxMSDffImportRec>> MSDffImportRecords; MSDffImportRecords m_Records; ///< Shape pointer, Shape ids and private data - tools::Rectangle aParentRect;///< Rectangle of the surrounding groups, + std::map<const SdrObject*, SvxMSDffImportRec*> m_ObjToRecMap; +public: + tools::Rectangle aParentRect;///< Rectangle of the surrounding groups, ///< which might have been provided externally explicit SvxMSDffImportData(const tools::Rectangle& rParentRect); @@ -279,6 +281,9 @@ struct MSFILTER_DLLPUBLIC SvxMSDffImportData SvxMSDffImportData( SvxMSDffImportData const & ) = delete; // MSVC2015 workaround ~SvxMSDffImportData(); bool empty() const { return m_Records.empty(); } + void insert(SvxMSDffImportRec* pImpRec); + void unmap(const SdrObject* pObj) { m_ObjToRecMap.erase(pObj); } + SvxMSDffImportRec* front() { return m_Records.begin()->get(); } size_t size() const { return m_Records.size(); } SvxMSDffImportRec* find(const SdrObject* pObj); MSDffImportRecords::const_iterator begin() const { return m_Records.begin(); } diff --git a/sw/source/filter/ww8/ww8graf.cxx b/sw/source/filter/ww8/ww8graf.cxx index d16d16cfa4af..53a3c3289f71 100644 --- a/sw/source/filter/ww8/ww8graf.cxx +++ b/sw/source/filter/ww8/ww8graf.cxx @@ -2753,10 +2753,9 @@ SwFrameFormat* SwWW8ImplReader::Read_GrafLayer( long nGrafAnchorCp ) */ if (!aData.empty()) { - for (MSDffImportRecords::const_iterator it = aData.begin(); - it != aData.end(); ++it) + for (const auto& it : aData) { - pRecord = it->get(); + pRecord = it.get(); if (pRecord->pObj && pRecord->aTextId.nTxBxS) { // #i52825# pRetFrameFormat can be NULL pRetFrameFormat = MungeTextIntoDrawBox( diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index befa3c2eb51a..1b735a0b02a0 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -1040,7 +1040,7 @@ SdrObject* SwMSDffManager::ProcessObj(SvStream& rSt, { // Complement Import Record List pImpRec->pObj = pObj; - rImportData.m_Records.insert(std::unique_ptr<SvxMSDffImportRec>(pImpRec)); + rImportData.insert(pImpRec); // Complement entry in Z Order List with a pointer to this Object // Only store objects which are not deep inside the tree _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
