Kaydet (Commit) 530331e4 authored tarafından Noel Grandin's avatar Noel Grandin

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: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst bfd26fd0
...@@ -70,7 +70,9 @@ using ::com::sun::star::container::XEnumeration; ...@@ -70,7 +70,9 @@ using ::com::sun::star::container::XEnumeration;
class XMLHints_Impl class XMLHints_Impl
{ {
private: private:
std::vector<std::unique_ptr<XMLHint_Impl>> m_Hints; std::vector<std::unique_ptr<XMLHint_Impl>> m_Hints;
std::unordered_map<OUString, XMLIndexMarkHint_Impl*> m_IndexHintsById;
uno::Reference<uno::XInterface> m_xCrossRefHeadingBookmark; uno::Reference<uno::XInterface> m_xCrossRefHeadingBookmark;
public: public:
...@@ -79,11 +81,23 @@ public: ...@@ -79,11 +81,23 @@ public:
m_Hints.push_back(std::move(pHint)); 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() std::vector<std::unique_ptr<XMLHint_Impl>> const& GetHints()
{ {
return m_Hints; 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() uno::Reference<uno::XInterface> & GetCrossRefHeadingBookmark()
{ {
return m_xCrossRefHeadingBookmark; return m_xCrossRefHeadingBookmark;
...@@ -1101,17 +1115,10 @@ void XMLIndexMarkImportContext_Impl::StartElement( ...@@ -1101,17 +1115,10 @@ void XMLIndexMarkImportContext_Impl::StartElement(
if (!sID.isEmpty()) if (!sID.isEmpty())
{ {
// if we have an ID, find the hint and set the end position // if we have an ID, find the hint and set the end position
for (const auto& rHintPtr : m_rHints.GetHints()) XMLIndexMarkHint_Impl *const pHint = m_rHints.GetIndexHintById(sID);
{ if (pHint)
XMLHint_Impl *const pHint = rHintPtr.get(); // set end and stop searching
if ( pHint->IsIndexMark() && pHint->SetEnd(xPos);
sID == static_cast<XMLIndexMarkHint_Impl *>(pHint)->GetID() )
{
// set end and stop searching
pHint->SetEnd(xPos);
break;
}
}
} }
// else: no ID -> ignore // else: no ID -> ignore
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment