tdf#66765 - FILESAVE: saving sheet with some queries in it takes forever
This takes the save time from 5m30 to 1s.
We were firing up the editeng stuff for every single style entry, when
most of the style entries share the same cell.
Change-Id: Id11af0b7f5646ff7ccdf1b85014fa384b0465054
Reviewed-on: https://gerrit.libreoffice.org/73239
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index 7a0c605..06917c2 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -2449,31 +2449,42 @@ void ScXMLExport::collectAutoStyles()
// stored text styles
// Calling createTextCursor fires up editeng, which is very slow, and often subsequent style entries
// refer to the same cell, so cache it.
ScAddress aPrevPos;
uno::Reference<beans::XPropertySet> xPrevCursorProp;
const std::vector<ScTextStyleEntry>& rTextEntries = pSheetData->GetTextStyles();
for (const auto& rTextEntry : rTextEntries)
{
ScAddress aPos = rTextEntry.maCellPos;
sal_Int32 nTable = aPos.Tab();
bool bCopySheet = pDoc->IsStreamValid( static_cast<SCTAB>(nTable) );
if (bCopySheet)
{
//! separate method AddStyleFromText needed?
//! cache sheet object
if (!bCopySheet)
continue;
//! separate method AddStyleFromText needed?
//! cache sheet object
uno::Reference<beans::XPropertySet> xCursorProp;
if (xPrevCursorProp && aPrevPos == aPos)
xCursorProp = xPrevCursorProp;
else
{
uno::Reference<table::XCellRange> xCellRange(xIndex->getByIndex(nTable), uno::UNO_QUERY);
uno::Reference<text::XSimpleText> xCellText(xCellRange->getCellByPosition(aPos.Col(), aPos.Row()), uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xCursorProp(xCellText->createTextCursor(), uno::UNO_QUERY);
ScCellTextCursor* pCursor = ScCellTextCursor::getImplementation( xCursorProp );
if (pCursor)
{
pCursor->SetSelection( rTextEntry.maSelection );
std::vector<XMLPropertyState> aPropStates(xTextPropMapper->Filter(xCursorProp));
OUString sName( rTextEntry.maName );
GetAutoStylePool()->AddNamed(sName, XML_STYLE_FAMILY_TEXT_TEXT, OUString(), aPropStates);
GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TEXT_TEXT, sName);
}
xCursorProp.set(xCellText->createTextCursor(), uno::UNO_QUERY);
}
ScCellTextCursor* pCursor = ScCellTextCursor::getImplementation( xCursorProp );
if (!pCursor)
continue;
pCursor->SetSelection( rTextEntry.maSelection );
std::vector<XMLPropertyState> aPropStates(xTextPropMapper->Filter(xCursorProp));
OUString sName( rTextEntry.maName );
GetAutoStylePool()->AddNamed(sName, XML_STYLE_FAMILY_TEXT_TEXT, OUString(), aPropStates);
GetAutoStylePool()->RegisterName(XML_STYLE_FAMILY_TEXT_TEXT, sName);
xPrevCursorProp = xCursorProp;
aPrevPos = aPos;
}
}