sd/inc/shapelist.hxx         |    2 ++
 sd/source/core/shapelist.cxx |   14 +++++++-------
 2 files changed, 9 insertions(+), 7 deletions(-)

New commits:
commit 632fc28fda03e312b2eb2d5843459b3ceee43534
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri Mar 8 21:47:47 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sat Mar 9 07:09:04 2024 +0100

    tdf#158773 add a set to sd::ShapeList
    
    because the std::list is atrociously bad at checking if the element
    already exists when the number of shapes gets large.
    
    Shaves 5% off the load time
    
    Change-Id: I6b8f972f8ff9559c363c084d91adea88b1267d3f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164597
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sd/inc/shapelist.hxx b/sd/inc/shapelist.hxx
index 6528cc073286..c93344835016 100644
--- a/sd/inc/shapelist.hxx
+++ b/sd/inc/shapelist.hxx
@@ -23,6 +23,7 @@
 #include <svx/sdrobjectuser.hxx>
 
 #include <list>
+#include <unordered_set>
 
 namespace sd
 {
@@ -65,6 +66,7 @@ namespace sd
         typedef std::list< SdrObject* > ListImpl;
         ListImpl maShapeList;
         ListImpl::iterator maIter;
+        std::unordered_set<const SdrObject*> maShapeSet;
     };
 }
 
diff --git a/sd/source/core/shapelist.cxx b/sd/source/core/shapelist.cxx
index 613286c9b9b7..a73044ba864f 100644
--- a/sd/source/core/shapelist.cxx
+++ b/sd/source/core/shapelist.cxx
@@ -38,8 +38,7 @@ ShapeList::~ShapeList()
 /** adds the given shape to this list */
 void ShapeList::addShape( SdrObject& rObject )
 {
-    ListImpl::iterator aIter( std::find( maShapeList.begin(), 
maShapeList.end(), &rObject ) );
-    if( aIter == maShapeList.end() )
+    if( maShapeSet.insert(&rObject).second )
     {
         maShapeList.push_back(&rObject);
         rObject.AddObjectUser( *this );
@@ -53,9 +52,9 @@ void ShapeList::addShape( SdrObject& rObject )
 /** removes the given shape from this list */
 void ShapeList::removeShape( SdrObject& rObject )
 {
-    ListImpl::iterator aIter( std::find( maShapeList.begin(), 
maShapeList.end(), &rObject ) );
-    if( aIter != maShapeList.end() )
+    if( maShapeSet.erase(&rObject) )
     {
+        ListImpl::iterator aIter( std::find( maShapeList.begin(), 
maShapeList.end(), &rObject ) );
         bool bIterErased = aIter == maIter;
 
         (*aIter)->RemoveObjectUser(*this);
@@ -76,6 +75,7 @@ void ShapeList::clear()
 {
     ListImpl aShapeList;
     aShapeList.swap( maShapeList );
+    maShapeSet.clear();
 
     for( auto& rpShape : aShapeList )
         rpShape->RemoveObjectUser(*this);
@@ -92,14 +92,14 @@ bool ShapeList::isEmpty() const
 /** returns true if given shape is part of this list */
 bool ShapeList::hasShape( SdrObject& rObject ) const
 {
-    return std::find( maShapeList.begin(), maShapeList.end(), &rObject )  != 
maShapeList.end();
+    return maShapeSet.contains( &rObject );
 }
 
 void ShapeList::ObjectInDestruction(const SdrObject& rObject)
 {
-    ListImpl::iterator aIter( std::find( maShapeList.begin(), 
maShapeList.end(), &rObject ) );
-    if( aIter != maShapeList.end() )
+    if( maShapeSet.erase(&rObject) )
     {
+        ListImpl::iterator aIter( std::find( maShapeList.begin(), 
maShapeList.end(), &rObject ) );
         bool bIterErased = aIter == maIter;
 
         aIter = maShapeList.erase( aIter );

Reply via email to