xmloff/source/style/impastpl.cxx |   88 +++++++++++++++++----------------------
 xmloff/source/style/impastpl.hxx |   14 ++----
 2 files changed, 45 insertions(+), 57 deletions(-)

New commits:
commit 51103b8396c3a0c0dc34afcf3c11bd93e4342163
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Tue Aug 30 20:45:02 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Aug 31 08:34:52 2022 +0200

    flatten data structures in SvXMLAutoStylePoolP_Impl a little
    
    set::set is already a node-based data structure, no need for
    more indirection
    
    Change-Id: Ib4083615696302621ce6f91059f99eee0849e4db
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139067
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/xmloff/source/style/impastpl.cxx b/xmloff/source/style/impastpl.cxx
index 40d65ed5dc8c..e103fc1c372a 100644
--- a/xmloff/source/style/impastpl.cxx
+++ b/xmloff/source/style/impastpl.cxx
@@ -257,14 +257,14 @@ struct ComparePartial
     const XMLAutoStyleFamily& rFamilyData;
 
     bool operator()(const vector< XMLPropertyState >& lhs,
-                    const std::unique_ptr<XMLAutoStylePoolProperties>& rhs) 
const
+                    const XMLAutoStylePoolProperties& rhs) const
     {
-        return rFamilyData.mxMapper->LessPartial(lhs, rhs->GetProperties());
+        return rFamilyData.mxMapper->LessPartial(lhs, rhs.GetProperties());
     }
-    bool operator()(const std::unique_ptr<XMLAutoStylePoolProperties>& lhs,
+    bool operator()(const XMLAutoStylePoolProperties& lhs,
                     const vector< XMLPropertyState >& rhs ) const
     {
-        return rFamilyData.mxMapper->LessPartial(lhs->GetProperties(), rhs);
+        return rFamilyData.mxMapper->LessPartial(lhs.GetProperties(), rhs);
     }
 };
 
@@ -275,18 +275,17 @@ struct ComparePartial
 
 bool XMLAutoStylePoolParent::Add( XMLAutoStyleFamily& rFamilyData, vector< 
XMLPropertyState >&& rProperties, OUString& rName, bool bDontSeek )
 {
-    XMLAutoStylePoolProperties *pProperties = nullptr;
+    PropertiesListType::iterator pProperties = m_PropertiesList.end();;
     auto [itBegin, itEnd] = std::equal_range(m_PropertiesList.begin(), 
m_PropertiesList.end(), rProperties, ComparePartial{rFamilyData});
     if (!bDontSeek)
         for (auto it = itBegin; it != itEnd; ++it)
-            if (rFamilyData.mxMapper->Equals((*it)->GetProperties(), 
rProperties))
-                pProperties = it->get();
+            if (rFamilyData.mxMapper->Equals(it->GetProperties(), rProperties))
+                pProperties = it;
 
     bool bAdded = false;
-    if( bDontSeek || !pProperties )
+    if( bDontSeek || pProperties == m_PropertiesList.end() )
     {
-        pProperties = new XMLAutoStylePoolProperties( rFamilyData, 
std::move(rProperties), msParent );
-        m_PropertiesList.insert(itBegin, 
std::unique_ptr<XMLAutoStylePoolProperties>(pProperties));
+        pProperties = m_PropertiesList.emplace(itBegin, rFamilyData, 
std::move(rProperties), msParent);
         bAdded = true;
     }
 
@@ -308,11 +307,9 @@ bool XMLAutoStylePoolParent::AddNamed( XMLAutoStyleFamily& 
rFamilyData, vector<
     
     auto it = std::lower_bound(m_PropertiesList.begin(), 
m_PropertiesList.end(), rProperties, ComparePartial{rFamilyData});
 
-    std::unique_ptr<XMLAutoStylePoolProperties> pProperties(
-        new XMLAutoStylePoolProperties(rFamilyData, std::move(rProperties), 
msParent));
+    it = m_PropertiesList.emplace(it, rFamilyData, std::move(rProperties), 
msParent);
     // ignore the generated name
-    pProperties->SetName( rName );
-    m_PropertiesList.insert(it, std::move(pProperties));
+    it->SetName( rName );
     return true;
 }
 
@@ -325,8 +322,8 @@ OUString XMLAutoStylePoolParent::Find( const 
XMLAutoStyleFamily& rFamilyData, co
     OUString sName;
     auto [itBegin,itEnd] = std::equal_range(m_PropertiesList.begin(), 
m_PropertiesList.end(), rProperties, ComparePartial{rFamilyData});
     for (auto it = itBegin; it != itEnd; ++it)
-        if (rFamilyData.mxMapper->Equals((*it)->GetProperties(), rProperties))
-            sName = (*it)->GetName();
+        if (rFamilyData.mxMapper->Equals(it->GetProperties(), rProperties))
+            sName = it->GetName();
 
     return sName;
 }
@@ -374,15 +371,15 @@ void SvXMLAutoStylePoolP_Impl::AddFamily(
     {
         // FIXME: do we really intend to replace the previous nFamily
         // entry in this case ?
-        SAL_WARN_IF( (*iter)->mxMapper != rMapper, "xmloff",
+        SAL_WARN_IF( iter->mxMapper != rMapper, "xmloff",
                      "Adding duplicate family " << rStrName <<
                      " with mismatching mapper ! " <<
-                     typeid((*iter)->mxMapper.get()).name() << " " <<
+                     typeid(iter->mxMapper.get()).name() << " " <<
                      typeid(*rMapper).name() );
     }
 #endif
 
-    m_FamilySet.insert(std::make_unique<XMLAutoStyleFamily>(nFamily, rStrName, 
rMapper, aPrefix, bAsFamily));
+    m_FamilySet.emplace(nFamily, rStrName, rMapper, aPrefix, bAsFamily);
 }
 
 void SvXMLAutoStylePoolP_Impl::SetFamilyPropSetMapper(
@@ -392,7 +389,7 @@ void SvXMLAutoStylePoolP_Impl::SetFamilyPropSetMapper(
     XMLAutoStyleFamily aTemp(nFamily);
     auto const iter = m_FamilySet.find(aTemp);
     if (iter != m_FamilySet.end())
-        (*iter)->mxMapper = rMapper;
+        const_cast<XMLAutoStyleFamily&>(*iter).mxMapper = rMapper;
 }
 
 // Adds a name to list
@@ -401,7 +398,7 @@ void SvXMLAutoStylePoolP_Impl::RegisterName( XmlStyleFamily 
nFamily, const OUStr
     XMLAutoStyleFamily aTemp(nFamily);
     auto const iter = m_FamilySet.find(aTemp);
     assert(iter != m_FamilySet.end()); // family must be known
-    (*iter)->maNameSet.insert(rName);
+    const_cast<XMLAutoStyleFamily&>(*iter).maNameSet.insert(rName);
 }
 
 // Adds a name to list
@@ -410,7 +407,7 @@ void SvXMLAutoStylePoolP_Impl::RegisterDefinedName( 
XmlStyleFamily nFamily, cons
     XMLAutoStyleFamily aTemp(nFamily);
     auto const iter = m_FamilySet.find(aTemp);
     assert(iter != m_FamilySet.end()); // family must be known
-    (*iter)->maReservedNameSet.insert(rName);
+    const_cast<XMLAutoStyleFamily&>(*iter).maReservedNameSet.insert(rName);
 }
 
 
@@ -426,10 +423,8 @@ void SvXMLAutoStylePoolP_Impl::GetRegisteredNames(
     vector<OUString> aNames;
 
     // iterate over families
-    for (auto const& aJ : m_FamilySet)
+    for (XMLAutoStyleFamily const & rFamily : m_FamilySet)
     {
-        XMLAutoStyleFamily &rFamily = *aJ;
-
         // iterate over names
         for (const auto& rName : rFamily.maNameSet)
         {
@@ -459,11 +454,10 @@ bool SvXMLAutoStylePoolP_Impl::Add(
     auto const iter = m_FamilySet.find(aTemp);
     assert(iter != m_FamilySet.end()); // family must be known
 
-    XMLAutoStyleFamily &rFamily = **iter;
+    XMLAutoStyleFamily &rFamily = const_cast<XMLAutoStyleFamily&>(*iter);
 
-    auto itPair = 
rFamily.m_ParentSet.insert(std::make_unique<XMLAutoStylePoolParent>(
-                        rParentName));
-    XMLAutoStylePoolParent& rParent = **itPair.first;
+    auto itPair = rFamily.m_ParentSet.emplace(rParentName);
+    XMLAutoStylePoolParent& rParent = 
const_cast<XMLAutoStylePoolParent&>(*itPair.first);
 
     bool bRet = false;
     if (rParent.Add(rFamily, std::move(rProperties), rName, bDontSeek))
@@ -485,11 +479,10 @@ bool SvXMLAutoStylePoolP_Impl::AddNamed(
     auto const iter = m_FamilySet.find(aTemp);
     assert(iter != m_FamilySet.end());  // family must be known
 
-    XMLAutoStyleFamily &rFamily = **iter;
+    XMLAutoStyleFamily &rFamily = const_cast<XMLAutoStyleFamily&>(*iter);
 
-    auto itPair = 
rFamily.m_ParentSet.insert(std::make_unique<XMLAutoStylePoolParent>(
-                        rParentName));
-    XMLAutoStylePoolParent& rParent = **itPair.first;
+    auto itPair = rFamily.m_ParentSet.emplace(rParentName);
+    XMLAutoStylePoolParent& rParent = 
const_cast<XMLAutoStylePoolParent&>(*itPair.first);
 
     bool bRet = false;
     if (rParent.AddNamed(rFamily, std::move(rProperties), rName))
@@ -515,12 +508,12 @@ OUString SvXMLAutoStylePoolP_Impl::Find( XmlStyleFamily 
nFamily,
     auto const iter = m_FamilySet.find(aTemp);
     assert(iter != m_FamilySet.end()); // family must be known
 
-    XMLAutoStyleFamily const& rFamily = **iter;
+    XMLAutoStyleFamily const& rFamily = *iter;
     XMLAutoStylePoolParent aTmp(rParent);
     auto const it2 = rFamily.m_ParentSet.find(aTmp);
     if (it2 != rFamily.m_ParentSet.end())
     {
-        sName = (*it2)->Find(rFamily, rProperties);
+        sName = it2->Find(rFamily, rProperties);
     }
 
     return sName;
@@ -530,16 +523,16 @@ std::vector<xmloff::AutoStyleEntry> 
SvXMLAutoStylePoolP_Impl::GetAutoStyleEntrie
 {
     std::vector<xmloff::AutoStyleEntry> rReturnVector;
 
-    for (std::unique_ptr<XMLAutoStyleFamily> const & rFamily : m_FamilySet)
+    for (XMLAutoStyleFamily const & rFamily : m_FamilySet)
     {
-        rtl::Reference<XMLPropertySetMapper> aPropertyMapper = 
rFamily->mxMapper->getPropertySetMapper();
-        for (auto const & rParent : rFamily->m_ParentSet)
+        rtl::Reference<XMLPropertySetMapper> aPropertyMapper = 
rFamily.mxMapper->getPropertySetMapper();
+        for (XMLAutoStylePoolParent const & rParent : rFamily.m_ParentSet)
         {
-            for (auto const & rProperty : rParent->GetPropertiesList())
+            for (XMLAutoStylePoolProperties const & rProperty : 
rParent.GetPropertiesList())
             {
                 rReturnVector.emplace_back();
                 xmloff::AutoStyleEntry & rEntry = rReturnVector.back();
-                for (XMLPropertyState const & rPropertyState : 
rProperty->GetProperties())
+                for (XMLPropertyState const & rPropertyState : 
rProperty.GetProperties())
                 {
                     if (rPropertyState.mnIndex >= 0)
                     {
@@ -583,7 +576,7 @@ void SvXMLAutoStylePoolP_Impl::exportXML(
     auto const iter = m_FamilySet.find(aTemp);
     assert(iter != m_FamilySet.end()); // family must be known
 
-    const XMLAutoStyleFamily &rFamily = **iter;
+    const XMLAutoStyleFamily &rFamily = *iter;
     sal_uInt32 nCount = rFamily.mnCount;
 
     if (!nCount)
@@ -593,18 +586,17 @@ void SvXMLAutoStylePoolP_Impl::exportXML(
     // which contains a parent-name and a SvXMLAutoStylePoolProperties_Impl
     std::vector<AutoStylePoolExport> aExpStyles(nCount);
 
-    for (auto const& it : rFamily.m_ParentSet)
+    for (XMLAutoStylePoolParent const& rParent : rFamily.m_ParentSet)
     {
-        XMLAutoStylePoolParent& rParent = *it;
         size_t nProperties = rParent.GetPropertiesList().size();
         for( size_t j = 0; j < nProperties; j++ )
         {
-            XMLAutoStylePoolProperties *const pProperties =
-                rParent.GetPropertiesList()[j].get();
-            sal_uInt32 nPos = pProperties->GetPos();
+            const XMLAutoStylePoolProperties & rProperties =
+                rParent.GetPropertiesList()[j];
+            sal_uInt32 nPos = rProperties.GetPos();
             assert(nPos < nCount);
             assert(!aExpStyles[nPos].mpProperties);
-            aExpStyles[nPos].mpProperties = pProperties;
+            aExpStyles[nPos].mpProperties = 
&const_cast<XMLAutoStylePoolProperties&>(rProperties);
             aExpStyles[nPos].mpParent = &rParent.GetParent();
         }
     }
@@ -711,7 +703,7 @@ void SvXMLAutoStylePoolP_Impl::exportXML(
 void SvXMLAutoStylePoolP_Impl::ClearEntries()
 {
     for (auto & aI : m_FamilySet)
-        aI->ClearEntries();
+        const_cast<XMLAutoStyleFamily&>(aI).ClearEntries();
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/style/impastpl.hxx b/xmloff/source/style/impastpl.hxx
index 213fba13774f..b8740f137df2 100644
--- a/xmloff/source/style/impastpl.hxx
+++ b/xmloff/source/style/impastpl.hxx
@@ -63,7 +63,7 @@ public:
 class XMLAutoStylePoolParent
 {
 public:
-    typedef std::vector<std::unique_ptr<XMLAutoStylePoolProperties>> 
PropertiesListType;
+    typedef std::vector<XMLAutoStylePoolProperties> PropertiesListType;
 
 private:
     OUString msParent;
@@ -86,10 +86,8 @@ public:
 
     const OUString& GetParent() const { return msParent; }
 
-    PropertiesListType& GetPropertiesList()
-    {
-        return m_PropertiesList;
-    }
+    PropertiesListType& GetPropertiesList() { return m_PropertiesList; }
+    const PropertiesListType& GetPropertiesList() const { return 
m_PropertiesList; }
 
     bool operator< (const XMLAutoStylePoolParent& rOther) const;
 };
@@ -98,8 +96,7 @@ public:
 
 struct XMLAutoStyleFamily
 {
-    typedef std::set<std::unique_ptr<XMLAutoStylePoolParent>,
-        comphelper::UniquePtrValueLess<XMLAutoStylePoolParent>> ParentSetType;
+    typedef std::set<XMLAutoStylePoolParent> ParentSetType;
 
     XmlStyleFamily mnFamily;
     OUString maStrFamilyName;
@@ -132,8 +129,7 @@ struct XMLAutoStyleFamily
 class SvXMLAutoStylePoolP_Impl
 {
     // A set that finds and sorts based only on mnFamily
-    typedef std::set<std::unique_ptr<XMLAutoStyleFamily>,
-            comphelper::UniquePtrValueLess<XMLAutoStyleFamily>> FamilySetType;
+    typedef std::set<XMLAutoStyleFamily> FamilySetType;
 
     SvXMLExport& rExport;
     FamilySetType m_FamilySet;

Reply via email to