summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-05-25 13:43:17 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-05-25 20:39:56 +0200
commit530331e4ac5b2351c3e72896342db103427088e5 (patch)
treed255693cafa6dd93ebb3f7f91093a7d0e42e3d46 /xmloff
parentbfd26fd04ba06d0eac3fb516c6548a1e6eacc6df (diff)
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.grandin@collabora.co.uk>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/source/text/txtparai.cxx29
1 files changed, 18 insertions, 11 deletions
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;