sw/inc/doc.hxx | 3 ++- sw/source/core/docnode/ndtbl.cxx | 7 +++++-- sw/source/core/unocore/unotbl.cxx | 33 ++++++++++++++++++--------------- sw/source/filter/xml/xmltbli.cxx | 5 +++-- 4 files changed, 28 insertions(+), 20 deletions(-)
New commits: commit 8a11aed9d43454cbb6b35d95f8896bf908ed5e82 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Fri Mar 31 17:38:42 2023 +0300 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Wed Apr 5 11:19:17 2023 +0200 tdf#154486: Use known name when inserting the table into the document ... instead of assinging a unique name at insertion time, then changing to the final value. As discussed in commit 1dd71d79e15bd8098e7c17c8fcea3748592a902f (tdf#154486: use importer-local map to deduplicate table names, 2023-03-31), the lookup for a unique table name has an O(n^2) complexity, and can make loading of thousands tables impossible. This changes import time from 23 s to ~2.5 s, and the time now depends on the number of tables linearly (e.g., 200 000 tables load in ~45 s). Change-Id: I0f2b5e37db2d370bccbc8c3430f895c864d9a4c2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149840 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> (cherry picked from commit 18e4c95a59809f4109f13934f2f072aee1cea000) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149874 Tested-by: Mike Kaganski <mike.kagan...@collabora.com> (cherry picked from commit b398c4b9f2e360a712884d69232228c8048a23b4) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149961 Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index 4a399b839896..428e64bcd9c7 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -1176,7 +1176,8 @@ public: const SwTableAutoFormat* pTAFormat = nullptr, const std::vector<sal_uInt16> *pColArr = nullptr, bool bCalledFromShell = false, - bool bNewModel = true ); + bool bNewModel = true, + const OUString& rTableName = {} ); // If index is in a table, return TableNode, else 0. static SwTableNode* IsIdxInTable( const SwNodeIndex& rIdx ); diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx index 30eab0bf5ece..946abf3eb289 100644 --- a/sw/source/core/docnode/ndtbl.cxx +++ b/sw/source/core/docnode/ndtbl.cxx @@ -340,7 +340,8 @@ const SwTable* SwDoc::InsertTable( const SwInsertTableOptions& rInsTableOpts, const SwTableAutoFormat* pTAFormat, const std::vector<sal_uInt16> *pColArr, bool bCalledFromShell, - bool bNewModel ) + bool bNewModel, + const OUString& rTableName ) { assert(nRows && "Table without line?"); assert(nCols && "Table without rows?"); @@ -357,7 +358,9 @@ const SwTable* SwDoc::InsertTable( const SwInsertTableOptions& rInsTableOpts, pColArr = nullptr; } - OUString aTableName = GetUniqueTableName(); + OUString aTableName = rTableName; + if (aTableName.isEmpty() || FindTableFormatByName(aTableName) != nullptr) + aTableName = GetUniqueTableName(); if( GetIDocumentUndoRedo().DoesUndo() ) { diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx index 882251965686..c2107079d290 100644 --- a/sw/source/core/unocore/unotbl.cxx +++ b/sw/source/core/unocore/unotbl.cxx @@ -2121,11 +2121,28 @@ SwXTextTable::attach(const uno::Reference<text::XTextRange> & xTextRange) pDoc->getIDocumentContentOperations().DeleteAndJoin(aPam); aPam.DeleteMark(); } + + OUString tableName; + if (const::uno::Any* pName; + m_pImpl->m_pTableProps->GetProperty(FN_UNO_TABLE_NAME, 0, pName)) + { + tableName = pName->get<OUString>(); + } + else if (!m_pImpl->m_sTableName.isEmpty()) + { + sal_uInt16 nIndex = 1; + tableName = m_pImpl->m_sTableName; + while (pDoc->FindTableFormatByName(tableName, true) && nIndex < USHRT_MAX) + tableName = m_pImpl->m_sTableName + OUString::number(nIndex++); + } + pTable = pDoc->InsertTable(SwInsertTableOptions( SwInsertTableFlags::Headline | SwInsertTableFlags::DefaultBorder | SwInsertTableFlags::SplitLayout, 0 ), *aPam.GetPoint(), m_pImpl->m_nRows, m_pImpl->m_nColumns, - text::HoriOrientation::FULL); + text::HoriOrientation::FULL, + nullptr, nullptr, false, true, + tableName); if(pTable) { // here, the properties of the descriptor need to be analyzed @@ -2135,20 +2152,6 @@ SwXTextTable::attach(const uno::Reference<text::XTextRange> & xTextRange) m_pImpl->SetFrameFormat(*pTableFormat); - if (!m_pImpl->m_sTableName.isEmpty()) - { - sal_uInt16 nIndex = 1; - OUString sTmpNameIndex(m_pImpl->m_sTableName); - while(pDoc->FindTableFormatByName(sTmpNameIndex, true) && nIndex < USHRT_MAX) - { - sTmpNameIndex = m_pImpl->m_sTableName + OUString::number(nIndex++); - } - pDoc->SetTableName( *pTableFormat, sTmpNameIndex); - } - - const::uno::Any* pName; - if (m_pImpl->m_pTableProps->GetProperty(FN_UNO_TABLE_NAME, 0, pName)) - setName(pName->get<OUString>()); m_pImpl->m_pTableProps.reset(); } pDoc->GetIDocumentUndoRedo().EndUndo( SwUndoId::END, nullptr ); diff --git a/sw/source/filter/xml/xmltbli.cxx b/sw/source/filter/xml/xmltbli.cxx index fec24079defc..acc01482cda4 100644 --- a/sw/source/filter/xml/xmltbli.cxx +++ b/sw/source/filter/xml/xmltbli.cxx @@ -53,6 +53,7 @@ #include <swtable.hxx> #include <swtblfmt.hxx> #include <pam.hxx> +#include <unoprnms.hxx> #include <unotbl.hxx> #include <unotextrange.hxx> #include <cellatr.hxx> @@ -1212,6 +1213,8 @@ SwXMLTableContext::SwXMLTableContext( SwXMLImport& rImport, if( xTable.is() ) { xTable->initialize( 1, 1 ); + if (css::uno::Reference<css::beans::XPropertySet> xPropSet{ xTable, css::uno::UNO_QUERY }) + xPropSet->setPropertyValue(UNO_NAME_TABLE_NAME, css::uno::Any(sTableName)); try { @@ -1251,8 +1254,6 @@ SwXMLTableContext::SwXMLTableContext( SwXMLImport& rImport, m_pTableNode = pTable->GetTableNode(); OSL_ENSURE( m_pTableNode, "table node missing" ); - pTableFrameFormat->SetFormatName( sTableName ); - SwTableLine *pLine1 = m_pTableNode->GetTable().GetTabLines()[0U]; m_pBox1 = pLine1->GetTabBoxes()[0U]; m_pSttNd1 = m_pBox1->GetSttNd();