summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-05-27 13:37:45 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-05-27 14:58:12 +0200
commit2d0eea0a79df9bc54e075c90ee7d6134b03250c0 (patch)
tree49ce2fc8748523bad37626f2eef3bf336ea5b926
parent01df224f574c5a7788df0f2aea3345166d6ce250 (diff)
we can search std::set without allocating on the heap
we just need to add some overloads to UniquePtrValueLess Change-Id: I91c395393a2de609c8f442de605d1dd2098dfae0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116248 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--include/comphelper/stl_types.hxx14
-rw-r--r--xmloff/source/style/impastpl.cxx36
2 files changed, 32 insertions, 18 deletions
diff --git a/include/comphelper/stl_types.hxx b/include/comphelper/stl_types.hxx
index 5e8a532a60b9..5693a83338f5 100644
--- a/include/comphelper/stl_types.hxx
+++ b/include/comphelper/stl_types.hxx
@@ -74,6 +74,20 @@ template<class T> struct UniquePtrValueLess
assert(rhs.get());
return (*lhs) < (*rhs);
}
+ // The following are so we can search in std::set without allocating a temporary entry on the heap
+ typedef bool is_transparent;
+ bool operator()(T const& lhs,
+ std::unique_ptr<T> const& rhs) const
+ {
+ assert(rhs.get());
+ return lhs < (*rhs);
+ }
+ bool operator()(std::unique_ptr<T> const& lhs,
+ T const& rhs) const
+ {
+ assert(lhs.get());
+ return (*lhs) < rhs;
+ }
};
/// by-value implementation of std::foo<std::unique_ptr<T>>::operator==
diff --git a/xmloff/source/style/impastpl.cxx b/xmloff/source/style/impastpl.cxx
index 0a3e2e97595f..b965b7a5a8f8 100644
--- a/xmloff/source/style/impastpl.cxx
+++ b/xmloff/source/style/impastpl.cxx
@@ -367,8 +367,8 @@ void SvXMLAutoStylePoolP_Impl::AddFamily(
}
#if OSL_DEBUG_LEVEL > 0
- std::unique_ptr<XMLAutoStyleFamily> pTemp(new XMLAutoStyleFamily(nFamily));
- auto const iter = m_FamilySet.find(pTemp);
+ XMLAutoStyleFamily aTemp(nFamily);
+ auto const iter = m_FamilySet.find(aTemp);
if (iter != m_FamilySet.end())
{
// FIXME: do we really intend to replace the previous nFamily
@@ -388,8 +388,8 @@ void SvXMLAutoStylePoolP_Impl::SetFamilyPropSetMapper(
XmlStyleFamily nFamily,
const rtl::Reference < SvXMLExportPropertyMapper > & rMapper )
{
- std::unique_ptr<XMLAutoStyleFamily> pTemp(new XMLAutoStyleFamily(nFamily));
- auto const iter = m_FamilySet.find(pTemp);
+ XMLAutoStyleFamily aTemp(nFamily);
+ auto const iter = m_FamilySet.find(aTemp);
if (iter != m_FamilySet.end())
(*iter)->mxMapper = rMapper;
}
@@ -397,8 +397,8 @@ void SvXMLAutoStylePoolP_Impl::SetFamilyPropSetMapper(
// Adds a name to list
void SvXMLAutoStylePoolP_Impl::RegisterName( XmlStyleFamily nFamily, const OUString& rName )
{
- std::unique_ptr<XMLAutoStyleFamily> pTemp(new XMLAutoStyleFamily(nFamily));
- auto const iter = m_FamilySet.find(pTemp);
+ XMLAutoStyleFamily aTemp(nFamily);
+ auto const iter = m_FamilySet.find(aTemp);
assert(iter != m_FamilySet.end()); // family must be known
// SAL_DEBUG("SvXMLAutoStylePoolP_Impl::RegisterName: " << nFamily << ", '" << rName << "'");
(*iter)->maNameSet.insert(rName);
@@ -407,8 +407,8 @@ void SvXMLAutoStylePoolP_Impl::RegisterName( XmlStyleFamily nFamily, const OUStr
// Adds a name to list
void SvXMLAutoStylePoolP_Impl::RegisterDefinedName( XmlStyleFamily nFamily, const OUString& rName )
{
- std::unique_ptr<XMLAutoStyleFamily> pTemp(new XMLAutoStyleFamily(nFamily));
- auto const iter = m_FamilySet.find(pTemp);
+ XMLAutoStyleFamily aTemp(nFamily);
+ auto const iter = m_FamilySet.find(aTemp);
assert(iter != m_FamilySet.end()); // family must be known
(*iter)->maReservedNameSet.insert(rName);
}
@@ -455,8 +455,8 @@ bool SvXMLAutoStylePoolP_Impl::Add(
OUString& rName, XmlStyleFamily nFamily, const OUString& rParentName,
const ::std::vector< XMLPropertyState >& rProperties, bool bDontSeek )
{
- std::unique_ptr<XMLAutoStyleFamily> pTemp(new XMLAutoStyleFamily(nFamily));
- auto const iter = m_FamilySet.find(pTemp);
+ XMLAutoStyleFamily aTemp(nFamily);
+ auto const iter = m_FamilySet.find(aTemp);
assert(iter != m_FamilySet.end()); // family must be known
XMLAutoStyleFamily &rFamily = **iter;
@@ -481,8 +481,8 @@ bool SvXMLAutoStylePoolP_Impl::AddNamed(
{
// get family and parent the same way as in Add()
- std::unique_ptr<XMLAutoStyleFamily> pTemp(new XMLAutoStyleFamily(nFamily));
- auto const iter = m_FamilySet.find(pTemp);
+ XMLAutoStyleFamily aTemp(nFamily);
+ auto const iter = m_FamilySet.find(aTemp);
assert(iter != m_FamilySet.end()); // family must be known
XMLAutoStyleFamily &rFamily = **iter;
@@ -511,13 +511,13 @@ OUString SvXMLAutoStylePoolP_Impl::Find( XmlStyleFamily nFamily,
{
OUString sName;
- std::unique_ptr<XMLAutoStyleFamily> pTemp(new XMLAutoStyleFamily(nFamily));
- auto const iter = m_FamilySet.find(pTemp);
+ XMLAutoStyleFamily aTemp(nFamily);
+ auto const iter = m_FamilySet.find(aTemp);
assert(iter != m_FamilySet.end()); // family must be known
XMLAutoStyleFamily const& rFamily = **iter;
- std::unique_ptr<XMLAutoStylePoolParent> pTmp(new XMLAutoStylePoolParent(rParent));
- auto const it2 = rFamily.m_ParentSet.find(pTmp);
+ XMLAutoStylePoolParent aTmp(rParent);
+ auto const it2 = rFamily.m_ParentSet.find(aTmp);
if (it2 != rFamily.m_ParentSet.end())
{
sName = (*it2)->Find(rFamily, rProperties);
@@ -579,8 +579,8 @@ void SvXMLAutoStylePoolP_Impl::exportXML(
const SvXMLAutoStylePoolP *pAntiImpl) const
{
// Get list of parents for current family (nFamily)
- std::unique_ptr<XMLAutoStyleFamily> pTemp(new XMLAutoStyleFamily(nFamily));
- auto const iter = m_FamilySet.find(pTemp);
+ XMLAutoStyleFamily aTemp(nFamily);
+ auto const iter = m_FamilySet.find(aTemp);
assert(iter != m_FamilySet.end()); // family must be known
const XMLAutoStyleFamily &rFamily = **iter;