[Libreoffice-commits] core.git: sw/source

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Fri Feb 17 22:41:00 UTC 2017


 sw/source/core/doc/docfmt.cxx       |   45 +++++++++++++++++++++---------------
 sw/source/core/unocore/unocoll.cxx  |   31 +++++++++++++++++-------
 sw/source/core/unocore/unostyle.cxx |   31 ++++++++++++------------
 3 files changed, 65 insertions(+), 42 deletions(-)

New commits:
commit 1334702ec3c92484c70954ce8474882ae5da6764
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Tue Feb 7 18:19:38 2017 +0100

    tdf#98665 optimize table format style access
    
    Rework GetTableFrameFormat and GetTableFrameFormatCount to a
    simpler implementation (searching forward and using c++11).
    
    Using GetTableFrameFormatCount to get the size and then in a loop
    call GetTableFrameFormat for every index, can get really slow as
    in each call we need to filter the whole collection. Through UNO
    we can't avoid this (without much more work), but for internal
    calls like SwXTextTableStyle::isInUse, we access the underlaying
    collection and iterate + filter ourselves. In the same way we can
    slightly optimize SwXTextTables::getByIndex UNO method (with
    removing the need to call GetTableFrameFormatCount).
    
    Change-Id: Ib8462c32311ccc162ec290fe4eec70820855a378
    Reviewed-on: https://gerrit.libreoffice.org/34008
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    Tested-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx
index 067dadc..6f70be5 100644
--- a/sw/source/core/doc/docfmt.cxx
+++ b/sw/source/core/doc/docfmt.cxx
@@ -771,34 +771,43 @@ SwDrawFrameFormat *SwDoc::MakeDrawFrameFormat( const OUString &rFormatName,
 
 size_t SwDoc::GetTableFrameFormatCount(bool bUsed) const
 {
-    size_t nCount = mpTableFrameFormatTable->size();
-    if(bUsed)
+    if (!bUsed)
     {
-        SwAutoFormatGetDocNode aGetHt( &GetNodes() );
-        for ( size_t i = nCount; i; )
-        {
-            if((*mpTableFrameFormatTable)[--i]->GetInfo( aGetHt ))
-                --nCount;
-        }
+        return mpTableFrameFormatTable->size();
+    }
+
+    SwAutoFormatGetDocNode aGetHt(&GetNodes());
+    size_t nCount = 0;
+    for (SwFrameFormat* const & pFormat : *mpTableFrameFormatTable)
+    {
+        if (!pFormat->GetInfo(aGetHt))
+            nCount++;
     }
     return nCount;
 }
 
-SwFrameFormat& SwDoc::GetTableFrameFormat(size_t nFormat, bool bUsed ) const
+SwFrameFormat& SwDoc::GetTableFrameFormat(size_t nFormat, bool bUsed) const
 {
-    size_t nRemoved = 0;
-    if(bUsed)
+    if (!bUsed)
     {
-        SwAutoFormatGetDocNode aGetHt( &GetNodes() );
-        for ( size_t i = 0; i <= nFormat; ++i )
+        return *((*mpTableFrameFormatTable)[nFormat]);
+    }
+
+    SwAutoFormatGetDocNode aGetHt(&GetNodes());
+
+    size_t index = 0;
+
+    for (SwFrameFormat* const & pFormat : *mpTableFrameFormatTable)
+    {
+        if (!pFormat->GetInfo(aGetHt))
         {
-            while ( (*mpTableFrameFormatTable)[ i + nRemoved]->GetInfo( aGetHt ))
-            {
-                nRemoved++;
-            }
+            if (index == nFormat)
+                return *pFormat;
+            else
+                index++;
         }
     }
-    return *((*mpTableFrameFormatTable)[nRemoved + nFormat]);
+    throw std::out_of_range("Format index out of range.");
 }
 
 SwTableFormat* SwDoc::MakeTableFrameFormat( const OUString &rFormatName,
diff --git a/sw/source/core/unocore/unocoll.cxx b/sw/source/core/unocore/unocoll.cxx
index f6db86e..0eea033 100644
--- a/sw/source/core/unocore/unocoll.cxx
+++ b/sw/source/core/unocore/unocoll.cxx
@@ -857,24 +857,37 @@ sal_Int32 SwXTextTables::getCount()
     return nRet;
 }
 
-uno::Any SAL_CALL SwXTextTables::getByIndex(sal_Int32 nIndex)
+uno::Any SAL_CALL SwXTextTables::getByIndex(sal_Int32 nInputIndex)
 {
     SolarMutexGuard aGuard;
     uno::Any aRet;
-    if(IsValid())
+    if (IsValid())
     {
-        if(0 <= nIndex && GetDoc()->GetTableFrameFormatCount(true) > static_cast<size_t>(nIndex))
+        if (nInputIndex < 0)
+            throw IndexOutOfBoundsException();
+
+        SwAutoFormatGetDocNode aGetHt( &GetDoc()->GetNodes() );
+        size_t nIndex = static_cast<size_t>(nInputIndex);
+        size_t nCurrentIndex = 0;
+
+        for (SwFrameFormat* const & pFormat : *GetDoc()->GetTableFrameFormats())
         {
-            SwFrameFormat& rFormat = GetDoc()->GetTableFrameFormat(nIndex, true);
-            uno::Reference< XTextTable >  xTable = SwXTextTables::GetObject(rFormat);
-            aRet <<= xTable;
+            if (!pFormat->GetInfo(aGetHt))
+            {
+                if (nCurrentIndex == nIndex)
+                {
+                    uno::Reference<XTextTable> xTable = SwXTextTables::GetObject(*pFormat);
+                    aRet <<= xTable;
+                    return aRet;
+                }
+                else
+                    nCurrentIndex++;
+            }
         }
-        else
-            throw IndexOutOfBoundsException();
+        throw IndexOutOfBoundsException();
     }
     else
         throw uno::RuntimeException();
-    return aRet;
 }
 
 uno::Any SwXTextTables::getByName(const OUString& rItemName)
diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 8c613e0..6bb8dc7 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -4400,23 +4400,24 @@ sal_Bool SAL_CALL SwXTextTableStyle::isInUse()
     if (!m_bPhysical)
         return false;
 
-    uno::Reference<text::XTextTablesSupplier> xTablesSupp(m_pDocShell->GetModel(), uno::UNO_QUERY);
-    if (!xTablesSupp.is())
-        return false;
-
-    uno::Reference<container::XIndexAccess> xTables(xTablesSupp->getTextTables(), uno::UNO_QUERY);
-    if (!xTables.is())
-        return false;
+    SwAutoFormatGetDocNode aGetHt( &m_pDocShell->GetDoc()->GetNodes() );
 
-    const sal_Int32 nCount = xTables->getCount();
-    for (sal_Int32 i=0; i < nCount; ++i)
+    for (SwFrameFormat* const & pFormat : *m_pDocShell->GetDoc()->GetTableFrameFormats())
     {
-        uno::Reference<beans::XPropertySet> xTablePropertySet;
-        xTables->getByIndex(i) >>= xTablePropertySet;
-        OUString sTableTemplateName;
-        if (xTablePropertySet.is() && (xTablePropertySet->getPropertyValue("TableTemplateName") >>= sTableTemplateName)
-            && sTableTemplateName == m_pTableAutoFormat->GetName())
-            return true;
+        if (!pFormat->GetInfo(aGetHt))
+        {
+            uno::Reference<text::XTextTable> xTable = SwXTextTables::GetObject(*pFormat);
+            if (xTable.is())
+            {
+                uno::Reference<beans::XPropertySet> xTablePropertySet(xTable, uno::UNO_QUERY);
+                OUString sTableTemplateName;
+                if (xTablePropertySet.is() && (xTablePropertySet->getPropertyValue("TableTemplateName") >>= sTableTemplateName)
+                    && sTableTemplateName == m_pTableAutoFormat->GetName())
+                {
+                    return true;
+                }
+            }
+        }
     }
 
     return false;


More information about the Libreoffice-commits mailing list