xmloff/source/text/txtparai.cxx | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)
New commits: commit 530331e4ac5b2351c3e72896342db103427088e5 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Sat May 25 13:43:17 2019 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Sat May 25 20:39:56 2019 +0200 tdf#125372 writer, file with lots of hints very slow to open, part1 Remove a chunk of O(n^2) work in XMLHints_Impl Change-Id: I6b391af630d83ddd563b66bc1ad1640cd78debc7 Reviewed-on: https://gerrit.libreoffice.org/72948 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/xmloff/source/text/txtparai.cxx b/xmloff/source/text/txtparai.cxx index f961f0694fc6..03ed99fecb5c 100644 --- a/xmloff/source/text/txtparai.cxx +++ b/xmloff/source/text/txtparai.cxx @@ -70,7 +70,9 @@ using ::com::sun::star::container::XEnumeration; class XMLHints_Impl { private: + std::vector<std::unique_ptr<XMLHint_Impl>> m_Hints; + std::unordered_map<OUString, XMLIndexMarkHint_Impl*> m_IndexHintsById; uno::Reference<uno::XInterface> m_xCrossRefHeadingBookmark; public: @@ -79,11 +81,23 @@ public: m_Hints.push_back(std::move(pHint)); } + void push_back(std::unique_ptr<XMLIndexMarkHint_Impl> pHint) + { + m_IndexHintsById.emplace(pHint->GetID(), pHint.get()); + m_Hints.push_back(std::move(pHint)); + } + std::vector<std::unique_ptr<XMLHint_Impl>> const& GetHints() { return m_Hints; } + XMLIndexMarkHint_Impl* GetIndexHintById(const OUString& sID) + { + auto it = m_IndexHintsById.find(sID); + return it == m_IndexHintsById.end() ? nullptr : it->second; + } + uno::Reference<uno::XInterface> & GetCrossRefHeadingBookmark() { return m_xCrossRefHeadingBookmark; @@ -1101,17 +1115,10 @@ void XMLIndexMarkImportContext_Impl::StartElement( if (!sID.isEmpty()) { // if we have an ID, find the hint and set the end position - for (const auto& rHintPtr : m_rHints.GetHints()) - { - XMLHint_Impl *const pHint = rHintPtr.get(); - if ( pHint->IsIndexMark() && - sID == static_cast<XMLIndexMarkHint_Impl *>(pHint)->GetID() ) - { - // set end and stop searching - pHint->SetEnd(xPos); - break; - } - } + XMLIndexMarkHint_Impl *const pHint = m_rHints.GetIndexHintById(sID); + if (pHint) + // set end and stop searching + pHint->SetEnd(xPos); } // else: no ID -> ignore break; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits