oox/inc/drawingml/textbody.hxx                 |    1 
 oox/inc/drawingml/textliststyle.hxx            |   19 +++++++-----
 oox/inc/drawingml/textparagraph.hxx            |    1 
 oox/source/drawingml/textliststyle.cxx         |   37 +++++++------------------
 oox/source/drawingml/textparagraph.cxx         |    2 -
 oox/source/ppt/presentationfragmenthandler.cxx |    2 -
 6 files changed, 26 insertions(+), 36 deletions(-)

New commits:
commit 306f6934ac6f0b012eaecd05bb4abb7c9d341993
Author:     Noel Grandin <n...@peralex.com>
AuthorDate: Wed Apr 14 12:51:59 2021 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Apr 14 17:04:52 2021 +0200

    reduce allocation in TextListStyle
    
    Change-Id: Id1bad0bf39b03bc6d4004c50c0f35b60d6753aa8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114084
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/oox/inc/drawingml/textbody.hxx b/oox/inc/drawingml/textbody.hxx
index 5e6d156e7ce4..093642f30d97 100644
--- a/oox/inc/drawingml/textbody.hxx
+++ b/oox/inc/drawingml/textbody.hxx
@@ -24,6 +24,7 @@
 #include <drawingml/textbodyproperties.hxx>
 #include <drawingml/textliststyle.hxx>
 #include <drawingml/shape3dproperties.hxx>
+#include <oox/helper/refvector.hxx>
 
 namespace com::sun::star::text {
     class XText;
diff --git a/oox/inc/drawingml/textliststyle.hxx 
b/oox/inc/drawingml/textliststyle.hxx
index 52cb29330877..ac84cc9d903d 100644
--- a/oox/inc/drawingml/textliststyle.hxx
+++ b/oox/inc/drawingml/textliststyle.hxx
@@ -21,11 +21,14 @@
 #define INCLUDED_OOX_DRAWINGML_TEXTLISTSTYLE_HXX
 
 #include <drawingml/textparagraphproperties.hxx>
-#include <oox/helper/refvector.hxx>
+#include <array>
+#include <memory>
 
 namespace oox::drawingml
 {
-typedef RefVector<TextParagraphProperties> TextParagraphPropertiesVector;
+constexpr int NUM_TEXT_LIST_STYLE_ENTRIES = 9;
+typedef std::array<std::shared_ptr<TextParagraphProperties>, 
NUM_TEXT_LIST_STYLE_ENTRIES>
+    TextParagraphPropertiesArray;
 
 class TextListStyle
 {
@@ -38,22 +41,22 @@ public:
 
     void apply(const TextListStyle& rTextListStyle);
 
-    const TextParagraphPropertiesVector& getListStyle() const { return 
maListStyle; };
-    TextParagraphPropertiesVector& getListStyle() { return maListStyle; };
+    const TextParagraphPropertiesArray& getListStyle() const { return 
maListStyle; };
+    TextParagraphPropertiesArray& getListStyle() { return maListStyle; };
 
-    const TextParagraphPropertiesVector& getAggregationListStyle() const
+    const TextParagraphPropertiesArray& getAggregationListStyle() const
     {
         return maAggregationListStyle;
     };
-    TextParagraphPropertiesVector& getAggregationListStyle() { return 
maAggregationListStyle; };
+    TextParagraphPropertiesArray& getAggregationListStyle() { return 
maAggregationListStyle; };
 
 #ifdef DBG_UTIL
     void dump() const;
 #endif
 
 private:
-    TextParagraphPropertiesVector maListStyle;
-    TextParagraphPropertiesVector maAggregationListStyle;
+    TextParagraphPropertiesArray maListStyle;
+    TextParagraphPropertiesArray maAggregationListStyle;
 };
 }
 
diff --git a/oox/inc/drawingml/textparagraph.hxx 
b/oox/inc/drawingml/textparagraph.hxx
index 22465355142c..5139c51b9b26 100644
--- a/oox/inc/drawingml/textparagraph.hxx
+++ b/oox/inc/drawingml/textparagraph.hxx
@@ -25,6 +25,7 @@
 #include <com/sun/star/text/XText.hpp>
 
 #include <oox/core/xmlfilterbase.hxx>
+#include <oox/helper/refvector.hxx>
 #include <drawingml/textrun.hxx>
 #include <drawingml/textliststyle.hxx>
 #include <drawingml/textparagraphproperties.hxx>
diff --git a/oox/source/drawingml/textliststyle.cxx 
b/oox/source/drawingml/textliststyle.cxx
index d900e3cef338..da170cae03eb 100644
--- a/oox/source/drawingml/textliststyle.cxx
+++ b/oox/source/drawingml/textliststyle.cxx
@@ -24,10 +24,10 @@ namespace oox::drawingml {
 
 TextListStyle::TextListStyle()
 {
-    for ( int i = 0; i < 9; i++ )
+    for ( int i = 0; i < NUM_TEXT_LIST_STYLE_ENTRIES; i++ )
     {
-        maListStyle.push_back( std::make_shared<TextParagraphProperties>( ) );
-        maAggregationListStyle.push_back( 
std::make_shared<TextParagraphProperties>( ) );
+        maListStyle[i] = std::make_shared<TextParagraphProperties>( );
+        maAggregationListStyle[i] = std::make_shared<TextParagraphProperties>( 
);
     }
 }
 
@@ -37,12 +37,10 @@ TextListStyle::~TextListStyle()
 
 TextListStyle::TextListStyle(const TextListStyle& rStyle)
 {
-    assert(rStyle.maListStyle.size() == 9);
-    assert(rStyle.maAggregationListStyle.size() == 9);
-    for ( size_t i = 0; i < 9; i++ )
+    for ( size_t i = 0; i < NUM_TEXT_LIST_STYLE_ENTRIES; i++ )
     {
-        maListStyle.push_back( std::make_shared<TextParagraphProperties>( 
*rStyle.maListStyle[i] ) );
-        maAggregationListStyle.push_back( 
std::make_shared<TextParagraphProperties>( *rStyle.maAggregationListStyle[i] ) 
);
+        maListStyle[i] = std::make_shared<TextParagraphProperties>( 
*rStyle.maListStyle[i] );
+        maAggregationListStyle[i] = std::make_shared<TextParagraphProperties>( 
*rStyle.maAggregationListStyle[i] );
     }
 }
 
@@ -50,11 +48,7 @@ TextListStyle& TextListStyle::operator=(const TextListStyle& 
rStyle)
 {
     if(this != &rStyle)
     {
-        assert(rStyle.maListStyle.size() == 9);
-        assert(rStyle.maAggregationListStyle.size() == 9);
-        assert(maListStyle.size() == 9);
-        assert(maAggregationListStyle.size() == 9);
-        for ( size_t i = 0; i < 9; i++ )
+        for ( size_t i = 0; i < NUM_TEXT_LIST_STYLE_ENTRIES; i++ )
         {
             *maListStyle[i] = *rStyle.maListStyle[i];
             *maAggregationListStyle[i] = *rStyle.maAggregationListStyle[i];
@@ -63,19 +57,10 @@ TextListStyle& TextListStyle::operator=(const 
TextListStyle& rStyle)
     return *this;
 }
 
-static void applyStyleList( const TextParagraphPropertiesVector& 
rSourceListStyle, TextParagraphPropertiesVector& rDestListStyle )
+static void applyStyleList( const TextParagraphPropertiesArray& 
rSourceListStyle, TextParagraphPropertiesArray& rDestListStyle )
 {
-    TextParagraphPropertiesVector::iterator aDestListStyleIter( 
rDestListStyle.begin() );
-    for (auto const& elemSource : rSourceListStyle)
-    {
-        if ( aDestListStyleIter != rDestListStyle.end() )
-        {
-            (*aDestListStyleIter)->apply(*elemSource);
-            ++aDestListStyleIter;
-        }
-        else
-            rDestListStyle.push_back( 
std::make_shared<TextParagraphProperties>(*elemSource) );
-    }
+    for ( size_t i = 0; i < NUM_TEXT_LIST_STYLE_ENTRIES; i++ )
+        rDestListStyle[i]->apply(*rSourceListStyle[i]);
 }
 
 void TextListStyle::apply( const TextListStyle& rTextListStyle )
@@ -87,7 +72,7 @@ void TextListStyle::apply( const TextListStyle& 
rTextListStyle )
 #ifdef DBG_UTIL
 void TextListStyle::dump() const
 {
-    for ( int i = 0; i < 9; i++ )
+    for ( int i = 0; i < NUM_TEXT_LIST_STYLE_ENTRIES; i++ )
     {
         SAL_INFO("oox.drawingml", "text list style level: " << i);
         maListStyle[i]->dump();
diff --git a/oox/source/drawingml/textparagraph.cxx 
b/oox/source/drawingml/textparagraph.cxx
index 8aa4d8895040..ca33caa9f767 100644
--- a/oox/source/drawingml/textparagraph.cxx
+++ b/oox/source/drawingml/textparagraph.cxx
@@ -66,7 +66,7 @@ TextParagraphPropertiesPtr TextParagraph::getParagraphStyle(
 
     SAL_INFO("oox", "TextParagraph::getParagraphStyle - level " << nLevel);
 
-    const TextParagraphPropertiesVector& rListStyle = 
rTextListStyle.getListStyle();
+    const TextParagraphPropertiesArray& rListStyle = 
rTextListStyle.getListStyle();
     if (nLevel >= static_cast< sal_Int16 >(rListStyle.size()))
         nLevel = 0;
     TextParagraphPropertiesPtr pTextParagraphStyle;
diff --git a/oox/source/ppt/presentationfragmenthandler.cxx 
b/oox/source/ppt/presentationfragmenthandler.cxx
index aced17a2523b..9e14a260b846 100644
--- a/oox/source/ppt/presentationfragmenthandler.cxx
+++ b/oox/source/ppt/presentationfragmenthandler.cxx
@@ -86,7 +86,7 @@ 
PresentationFragmentHandler::PresentationFragmentHandler(XmlFilterBase& rFilter,
     , mpTextListStyle( std::make_shared<TextListStyle>() )
     , mbCommentAuthorsRead(false)
 {
-    TextParagraphPropertiesVector& rParagraphDefaultsVector( 
mpTextListStyle->getListStyle() );
+    TextParagraphPropertiesArray& rParagraphDefaultsVector( 
mpTextListStyle->getListStyle() );
     for (auto const& elem : rParagraphDefaultsVector)
     {
         // ppt is having zero bottom margin per default, whereas OOo is 0,5cm,
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to