Kaydet (Commit) 1334702e authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Tomaž Vajngerl

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/34008Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
Tested-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst 5b302286
......@@ -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,
......
......@@ -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)
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment