nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java
 |    2 
 
nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/Library.java
          |    4 +
 writerfilter/source/dmapper/DomainMapper.cxx                                   
             |   10 ++
 writerfilter/source/dmapper/DomainMapper.hxx                                   
             |    3 
 writerfilter/source/dmapper/DomainMapper_Impl.cxx                              
             |   37 ++++++++++
 writerfilter/source/dmapper/DomainMapper_Impl.hxx                              
             |    5 +
 writerfilter/source/dmapper/StyleSheetTable.cxx                                
             |   22 -----
 7 files changed, 63 insertions(+), 20 deletions(-)

New commits:
commit ecbdb403d16f6b0aeb8b543e069e9d82adf10437
Author:     Noel Grandin <n...@peralex.com>
AuthorDate: Thu Jun 17 18:44:01 2021 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Jun 17 20:44:22 2021 +0200

     tdf#135316 docx open performance, cache next character style name
    
    so we don't have to scan the list repeatedly, which is O(n^2)
    
    This takes my load time from 37s to 22s
    
    Change-Id: I0df2f2ace82f5cd6287c7ded796b02c5242269ec
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117396
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/writerfilter/source/dmapper/DomainMapper.cxx 
b/writerfilter/source/dmapper/DomainMapper.cxx
index fd341dd4d765..39b118e108f0 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -4127,6 +4127,16 @@ void DomainMapper::commentProps(const OUString& sId, 
const CommentProperties& rP
     m_pImpl->commentProps(sId, rProps);
 }
 
+css::uno::Reference<css::container::XNameContainer> const & 
DomainMapper::GetCharacterStyles()
+{
+    return m_pImpl->GetCharacterStyles();
+}
+
+OUString DomainMapper::GetUnusedCharacterStyleName()
+{
+    return m_pImpl->GetUnusedCharacterStyleName();
+}
+
 } //namespace writerfilter
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/dmapper/DomainMapper.hxx 
b/writerfilter/source/dmapper/DomainMapper.hxx
index 086e7f695db2..e76014737cf3 100644
--- a/writerfilter/source/dmapper/DomainMapper.hxx
+++ b/writerfilter/source/dmapper/DomainMapper.hxx
@@ -133,6 +133,9 @@ public:
 
     virtual void commentProps(const OUString& sId, const CommentProperties& 
rProps) override;
 
+    css::uno::Reference<css::container::XNameContainer> const & 
GetCharacterStyles();
+    OUString GetUnusedCharacterStyleName();
+
 private:
     // Stream
     virtual void lcl_startSectionGroup() override;
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 7b2903f9f4b2..e02549daf430 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -442,6 +442,43 @@ OUString DomainMapper_Impl::GetUnusedPageStyleName()
     return sPageStyleName;
 }
 
+uno::Reference< container::XNameContainer > const &  
DomainMapper_Impl::GetCharacterStyles()
+{
+    if(!m_xCharacterStyles.is())
+    {
+        uno::Reference< style::XStyleFamiliesSupplier > xSupplier( 
m_xTextDocument, uno::UNO_QUERY );
+        if (xSupplier.is())
+            xSupplier->getStyleFamilies()->getByName("CharacterStyles") >>= 
m_xCharacterStyles;
+    }
+    return m_xCharacterStyles;
+}
+
+OUString DomainMapper_Impl::GetUnusedCharacterStyleName()
+{
+    static const char cListLabel[] = "ListLabel ";
+    if (!m_xNextUnusedCharacterStyleNo)
+    {
+        //search for all character styles with the name sListLabel + <index>
+        const uno::Sequence< OUString > aCharacterStyleNames = 
GetCharacterStyles()->getElementNames();
+        sal_Int32         nMaxIndex       = 0;
+        for ( const auto& rStyleName : aCharacterStyleNames )
+        {
+            OUString sSuffix;
+            if ( rStyleName.startsWith( cListLabel, &sSuffix ) )
+            {
+                sal_Int32 nSuffix = sSuffix.toInt32();
+                if( nSuffix > 0 && nSuffix > nMaxIndex )
+                    nMaxIndex = nSuffix;
+            }
+        }
+        m_xNextUnusedCharacterStyleNo = nMaxIndex + 1;
+    }
+
+    OUString sPageStyleName = cListLabel + OUString::number( 
*m_xNextUnusedCharacterStyleNo );
+    *m_xNextUnusedCharacterStyleNo = *m_xNextUnusedCharacterStyleNo + 1;
+    return sPageStyleName;
+}
+
 uno::Reference< text::XText > const & DomainMapper_Impl::GetBodyText()
 {
     if(!m_xBodyText.is())
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index 99d266968c72..5212653dcd47 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -458,6 +458,9 @@ private:
     css::uno::Reference<css::container::XNameContainer> m_xPageStyles1;
     // cache next available number, expensive to repeatedly compute
     std::optional<int> m_xNextUnusedPageStyleNo;
+    css::uno::Reference<css::container::XNameContainer> m_xCharacterStyles;
+    // cache next available number, expensive to repeatedly compute
+    std::optional<int> m_xNextUnusedCharacterStyleNo;
     css::uno::Reference<css::text::XText> m_xBodyText;
     css::uno::Reference<css::text::XTextContent> m_xEmbedded;
 
@@ -631,6 +634,8 @@ public:
 
     css::uno::Reference<css::container::XNameContainer> const & 
GetPageStyles();
     OUString GetUnusedPageStyleName();
+    css::uno::Reference<css::container::XNameContainer> const & 
GetCharacterStyles();
+    OUString GetUnusedCharacterStyleName();
     css::uno::Reference<css::text::XText> const & GetBodyText();
     const css::uno::Reference<css::lang::XMultiServiceFactory>& 
GetTextFactory() const
     {
diff --git a/writerfilter/source/dmapper/StyleSheetTable.cxx 
b/writerfilter/source/dmapper/StyleSheetTable.cxx
index e1329da95852..361914a60aea 100644
--- a/writerfilter/source/dmapper/StyleSheetTable.cxx
+++ b/writerfilter/source/dmapper/StyleSheetTable.cxx
@@ -1602,26 +1602,10 @@ OUString StyleSheetTable::getOrCreateCharStyle( 
PropertyValueVector_t& rCharProp
     // Don't try to reuse an existing character style if requested.
     if( !sListLabel.isEmpty() && !bAlwaysCreate)
         return sListLabel;
-    const char cListLabel[] = "ListLabel ";
-    uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier( 
m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
-    uno::Reference< container::XNameAccess > xStyleFamilies = 
xStylesSupplier->getStyleFamilies();
-    uno::Reference<container::XNameContainer> xCharStyles;
-    xStyleFamilies->getByName("CharacterStyles") >>= xCharStyles;
-    //search for all character styles with the name sListLabel + <index>
-    sal_Int32 nStyleFound = 0;
-    const uno::Sequence< OUString > aStyleNames = 
xCharStyles->getElementNames();
-    for( const auto& rStyleName : aStyleNames )
-    {
-        OUString sSuffix;
-        if( rStyleName.startsWith( cListLabel, &sSuffix ) )
-        {
-            sal_Int32 nSuffix = sSuffix.toInt32();
-            if( nSuffix > 0 && nSuffix > nStyleFound )
-                nStyleFound = nSuffix;
-        }
-    }
-    sListLabel = cListLabel + OUString::number( ++nStyleFound );
+
     //create a new one otherwise
+    const uno::Reference< container::XNameContainer >& xCharStyles = 
m_pImpl->m_rDMapper.GetCharacterStyles();
+    sListLabel = m_pImpl->m_rDMapper.GetUnusedCharacterStyleName();
     uno::Reference< lang::XMultiServiceFactory > xDocFactory( 
m_pImpl->m_xTextDocument, uno::UNO_QUERY_THROW );
     try
     {
commit 72cd9250a80bc2db61b1f90217f2f7fdc0d51bcc
Author:     Todor Balabanov <todor.balaba...@gmail.com>
AuthorDate: Wed Jun 16 11:16:40 2021 +0300
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Jun 17 20:41:37 2021 +0200

    A separate function for getting a random search point is a little bit 
clearer.
    
    Change-Id: I2d7471440cdee096b09ce704cbea3d5311f984c8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117289
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git 
a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java
 
b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java
index 0e68f856d912..5dedc8052ec7 100644
--- 
a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java
+++ 
b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/deps/behavior/DEGTBehavior.java
@@ -118,7 +118,7 @@ public class DEGTBehavior extends AbsGTBehavior implements 
ILibEngine {
   private SearchPoint[] getReferPoints() {
     SearchPoint[] referPoints = new SearchPoint[DVNum * 2];
     for (int i = 0; i < referPoints.length; i++) {
-      referPoints[i] = 
socialLib.getSelectedPoint(RandomGenerator.intRangeRandom(0, 
socialLib.getPopSize() - 1));
+      referPoints[i] = socialLib.getRandomPoint();
     }
     return referPoints;
   }
diff --git 
a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/Library.java
 
b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/Library.java
index 247d4908c420..76e57ac76077 100644
--- 
a/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/Library.java
+++ 
b/nlpsolver/ThirdParty/EvolutionarySolver/src/net/adaptivebox/knowledge/Library.java
@@ -56,6 +56,10 @@ public class Library {
     return libPoints[index];
   }
 
+  public SearchPoint getRandomPoint() {
+    return libPoints[RandomGenerator.intRangeRandom(0, libPoints.length - 1)];
+  }
+
   public static boolean replace(IGoodnessCompareEngine comparator, SearchPoint 
outPoint,
       SearchPoint tobeReplacedPoint) {
     boolean isBetter = false;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to