summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2017-02-07 18:19:38 +0100
committerTomaž Vajngerl <quikee@gmail.com>2017-02-17 22:40:37 +0000
commit1334702ec3c92484c70954ce8474882ae5da6764 (patch)
tree27fd858cf9ca2bf394c4d35c3bda9de56ccfbcab
parent5b3022860abfe7eefd2e25b60b5b2a563b42b3c0 (diff)
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@gmail.com> Tested-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--sw/source/core/doc/docfmt.cxx45
-rw-r--r--sw/source/core/unocore/unocoll.cxx31
-rw-r--r--sw/source/core/unocore/unostyle.cxx31
3 files changed, 65 insertions, 42 deletions
diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx
index 067dadcb72dd..6f70be50303d 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 f6db86e07ea9..0eea0338b447 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 8c613e0f7ca8..6bb8dc7d87d4 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;