summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2019-04-18 15:13:19 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2019-04-19 13:19:31 +0200
commit1a5b12aa5da2c718848d3cc5d9bce7bfcdeacf54 (patch)
tree25044edc2afb99073ba6bef8d181dadbb6a53467 /xmloff
parenteaaaad0e21edb27edaa865eee03696f007cd8010 (diff)
optimise find/insert pattern
if we're doing a find/insert on a set or a map, it is better to just do a conditional insert/emplace operation than triggering two lookups. Change-Id: I80da5097f5a89fe30fa348ce5b6e747c34287a8d Reviewed-on: https://gerrit.libreoffice.org/70937 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/source/style/impastpl.cxx23
-rw-r--r--xmloff/source/style/xmlnumfi.cxx12
2 files changed, 7 insertions, 28 deletions
diff --git a/xmloff/source/style/impastpl.cxx b/xmloff/source/style/impastpl.cxx
index 191f178635ea..1b574adc8b97 100644
--- a/xmloff/source/style/impastpl.cxx
+++ b/xmloff/source/style/impastpl.cxx
@@ -511,16 +511,9 @@ bool SvXMLAutoStylePoolP_Impl::Add(
XMLAutoStyleFamily &rFamily = **iter;
std::unique_ptr<XMLAutoStylePoolParent> pTmp(new XMLAutoStylePoolParent(rParentName));
- auto it2 = rFamily.m_ParentSet.find(pTmp);
- if (it2 == rFamily.m_ParentSet.end())
- {
- std::pair<XMLAutoStyleFamily::ParentSetType::iterator,bool> r =
- rFamily.m_ParentSet.insert(std::make_unique<XMLAutoStylePoolParent>(
+ auto itPair = rFamily.m_ParentSet.insert(std::make_unique<XMLAutoStylePoolParent>(
rParentName));
- it2 = r.first;
- }
-
- XMLAutoStylePoolParent& rParent = **it2;
+ XMLAutoStylePoolParent& rParent = **itPair.first;
bool bRet = false;
if (rParent.Add(rFamily, rProperties, rName, bDontSeek))
@@ -544,17 +537,9 @@ bool SvXMLAutoStylePoolP_Impl::AddNamed(
XMLAutoStyleFamily &rFamily = **iter;
- std::unique_ptr<XMLAutoStylePoolParent> pTmp(new XMLAutoStylePoolParent(rParentName));
- auto it2 = rFamily.m_ParentSet.find(pTmp);
- if (it2 == rFamily.m_ParentSet.end())
- {
- std::pair<XMLAutoStyleFamily::ParentSetType::iterator,bool> r =
- rFamily.m_ParentSet.insert(std::make_unique<XMLAutoStylePoolParent>(
+ auto itPair = rFamily.m_ParentSet.insert(std::make_unique<XMLAutoStylePoolParent>(
rParentName));
- it2 = r.first;
- }
-
- XMLAutoStylePoolParent& rParent = **it2;
+ XMLAutoStylePoolParent& rParent = **itPair.first;
bool bRet = false;
if (rParent.AddNamed(rFamily, rProperties, rName))
diff --git a/xmloff/source/style/xmlnumfi.cxx b/xmloff/source/style/xmlnumfi.cxx
index 1a7b81c6f311..100ada1d3ec7 100644
--- a/xmloff/source/style/xmlnumfi.cxx
+++ b/xmloff/source/style/xmlnumfi.cxx
@@ -1083,16 +1083,10 @@ void SvXMLNumFmtElementContext::AddEmbeddedElement( sal_Int32 nFormatPos, const
if (rContent.isEmpty())
return;
- auto const iter(aNumInfo.m_EmbeddedElements.find(nFormatPos));
- if (iter == aNumInfo.m_EmbeddedElements.end())
- {
- aNumInfo.m_EmbeddedElements.insert(std::make_pair(nFormatPos, rContent));
- }
- else
- {
+ auto iterPair = aNumInfo.m_EmbeddedElements.emplace(nFormatPos, rContent);
+ if (!iterPair.second)
// there's already an element at this position - append text to existing element
- iter->second += rContent;
- }
+ iterPair.first->second += rContent;
}
void SvXMLNumFmtElementContext::EndElement()