Kaydet (Commit) 832bee9a authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Update script types of all cells in sort range ahead of time.

To ensure that there is no SC_SCRIPTTYPE_UNKNOWN in the sort range,
the presence of which would slow down during AdjustRowHeight().

This only adds a tiny overhead (0.3 second) and cuts the duration of
AdjustRowHeight() from 15 seconds to 5 seconds.

Change-Id: I145e901225ef1136f53c6f682ffed3902099859c
üst 94cf534a
...@@ -499,6 +499,7 @@ public: ...@@ -499,6 +499,7 @@ public:
sc::CellStoreType::iterator itr); sc::CellStoreType::iterator itr);
void SetScriptType( SCROW nRow, sal_uInt8 nType ); void SetScriptType( SCROW nRow, sal_uInt8 nType );
void UpdateScriptTypes( SCROW nRow1, SCROW nRow2 );
size_t GetFormulaHash( SCROW nRow ) const; size_t GetFormulaHash( SCROW nRow ) const;
......
...@@ -2060,6 +2060,7 @@ public: ...@@ -2060,6 +2060,7 @@ public:
sal_uInt8 GetScriptType( const ScAddress& rPos ) const; sal_uInt8 GetScriptType( const ScAddress& rPos ) const;
void SetScriptType( const ScAddress& rPos, sal_uInt8 nType ); void SetScriptType( const ScAddress& rPos, sal_uInt8 nType );
void UpdateScriptTypes( const ScAddress& rPos, SCCOL nColSize, SCROW nRowSize );
size_t GetFormulaHash( const ScAddress& rPos ) const; size_t GetFormulaHash( const ScAddress& rPos ) const;
......
...@@ -864,6 +864,7 @@ public: ...@@ -864,6 +864,7 @@ public:
sal_uInt8 GetScriptType( SCCOL nCol, SCROW nRow ) const; sal_uInt8 GetScriptType( SCCOL nCol, SCROW nRow ) const;
void SetScriptType( SCCOL nCol, SCROW nRow, sal_uInt8 nType ); void SetScriptType( SCCOL nCol, SCROW nRow, sal_uInt8 nType );
void UpdateScriptTypes( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 );
sal_uInt8 GetRangeScriptType( sc::ColumnBlockPosition& rBlockPos, SCCOL nCol, SCROW nRow1, SCROW nRow2 ); sal_uInt8 GetRangeScriptType( sc::ColumnBlockPosition& rBlockPos, SCCOL nCol, SCROW nRow1, SCROW nRow2 );
......
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
#include <conditio.hxx> #include <conditio.hxx>
#include <formulagroup.hxx> #include <formulagroup.hxx>
#include <tokenarray.hxx> #include <tokenarray.hxx>
#include <globalnames.hxx>
#include <scitems.hxx>
#include <cellform.hxx>
#include <svl/sharedstringpool.hxx> #include <svl/sharedstringpool.hxx>
...@@ -721,4 +724,105 @@ void ScColumn::PostprocessRangeNameUpdate( sc::CompileFormulaContext& rCompileCx ...@@ -721,4 +724,105 @@ void ScColumn::PostprocessRangeNameUpdate( sc::CompileFormulaContext& rCompileCx
std::for_each(aGroups.begin(), aGroups.end(), aFunc); std::for_each(aGroups.begin(), aGroups.end(), aFunc);
} }
namespace {
class ScriptTypeUpdater
{
ScColumn& mrCol;
sc::CellTextAttrStoreType& mrTextAttrs;
sc::CellTextAttrStoreType::iterator miPosAttr;
ScConditionalFormatList* mpCFList;
SvNumberFormatter* mpFormatter;
ScAddress maPos;
bool mbUpdated;
private:
void updateScriptType( size_t nRow, ScRefCellValue& rCell )
{
sc::CellTextAttrStoreType::position_type aAttrPos = mrTextAttrs.position(miPosAttr, nRow);
miPosAttr = aAttrPos.first;
if (aAttrPos.first->type != sc::element_type_celltextattr)
return;
sc::CellTextAttr& rAttr = sc::celltextattr_block::at(*aAttrPos.first->data, aAttrPos.second);
if (rAttr.mnScriptType != SC_SCRIPTTYPE_UNKNOWN)
// Script type already deteremined. Skip it.
return;
const ScPatternAttr* pPat = mrCol.GetPattern(nRow);
if (!pPat)
// In theory this should never return NULL. But let's be safe.
return;
const SfxItemSet* pCondSet = NULL;
if (mpCFList)
{
maPos.SetRow(nRow);
const ScCondFormatItem& rItem =
static_cast<const ScCondFormatItem&>(pPat->GetItem(ATTR_CONDITIONAL));
const std::vector<sal_uInt32>& rData = rItem.GetCondFormatData();
pCondSet = mrCol.GetDoc().GetCondResult(rCell, maPos, *mpCFList, rData);
}
OUString aStr;
Color* pColor;
sal_uLong nFormat = pPat->GetNumberFormat(mpFormatter, pCondSet);
ScCellFormat::GetString(rCell, nFormat, aStr, &pColor, *mpFormatter, &mrCol.GetDoc());
rAttr.mnScriptType = mrCol.GetDoc().GetStringScriptType(aStr);
mbUpdated = true;
}
public:
ScriptTypeUpdater( ScColumn& rCol ) :
mrCol(rCol),
mrTextAttrs(rCol.GetCellAttrStore()),
miPosAttr(mrTextAttrs.begin()),
mpCFList(rCol.GetDoc().GetCondFormList(rCol.GetTab())),
mpFormatter(rCol.GetDoc().GetFormatTable()),
maPos(rCol.GetCol(), 0, rCol.GetTab()),
mbUpdated(false)
{}
void operator() ( size_t nRow, double fVal )
{
ScRefCellValue aCell(fVal);
updateScriptType(nRow, aCell);
}
void operator() ( size_t nRow, const svl::SharedString& rStr )
{
ScRefCellValue aCell(&rStr);
updateScriptType(nRow, aCell);
}
void operator() ( size_t nRow, const EditTextObject* pText )
{
ScRefCellValue aCell(pText);
updateScriptType(nRow, aCell);
}
void operator() ( size_t nRow, const ScFormulaCell* pCell )
{
ScRefCellValue aCell(const_cast<ScFormulaCell*>(pCell));
updateScriptType(nRow, aCell);
}
bool isUpdated() const { return mbUpdated; }
};
}
void ScColumn::UpdateScriptTypes( SCROW nRow1, SCROW nRow2 )
{
if (!ValidRow(nRow1) || !ValidRow(nRow2) || nRow1 > nRow2)
return;
ScriptTypeUpdater aFunc(*this);
sc::ParseAllNonEmpty(maCells.begin(), maCells, nRow1, nRow2, aFunc);
if (aFunc.isUpdated())
CellStorageModified();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -270,4 +270,13 @@ void ScDocument::SharePooledResources( ScDocument* pSrcDoc ) ...@@ -270,4 +270,13 @@ void ScDocument::SharePooledResources( ScDocument* pSrcDoc )
mpCellStringPool = pSrcDoc->mpCellStringPool; mpCellStringPool = pSrcDoc->mpCellStringPool;
} }
void ScDocument::UpdateScriptTypes( const ScAddress& rPos, SCCOL nColSize, SCROW nRowSize )
{
ScTable* pTab = FetchTable(rPos.Tab());
if (!pTab)
return;
pTab->UpdateScriptTypes(rPos.Col(), rPos.Row(), rPos.Col()+nColSize-1, rPos.Row()+nRowSize-1);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -101,4 +101,13 @@ void ScTable::PostprocessRangeNameUpdate( sc::CompileFormulaContext& rCompileCxt ...@@ -101,4 +101,13 @@ void ScTable::PostprocessRangeNameUpdate( sc::CompileFormulaContext& rCompileCxt
aCol[i].PostprocessRangeNameUpdate(rCompileCxt); aCol[i].PostprocessRangeNameUpdate(rCompileCxt);
} }
void ScTable::UpdateScriptTypes( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2 )
{
if (!ValidCol(nCol1) || !ValidCol(nCol2) || nCol1 > nCol2)
return;
for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
aCol[nCol].UpdateScriptTypes(nRow1, nRow2);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -490,6 +490,14 @@ bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam, ...@@ -490,6 +490,14 @@ bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam,
WaitObject aWait( rDocShell.GetActiveDialogParent() ); WaitObject aWait( rDocShell.GetActiveDialogParent() );
// Calculate the script types for all cells in the sort range beforehand.
// This will speed up the row height adjustment that takes place after the
// sort.
pDoc->UpdateScriptTypes(
ScAddress(rSortParam.nCol1,rSortParam.nRow1,nTab),
rSortParam.nCol2-rSortParam.nCol1+1,
rSortParam.nRow2-rSortParam.nRow1+1);
bool bRepeatQuery = false; // bestehenden Filter wiederholen? bool bRepeatQuery = false; // bestehenden Filter wiederholen?
ScQueryParam aQueryParam; ScQueryParam aQueryParam;
pDBData->GetQueryParam( aQueryParam ); pDBData->GetQueryParam( aQueryParam );
...@@ -651,7 +659,6 @@ bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam, ...@@ -651,7 +659,6 @@ bool ScDBDocFunc::Sort( SCTAB nTab, const ScSortParam& rSortParam,
rDocShell.PostPaint(ScRange(nStartX, nStartY, nTab, nEndX, nEndY, nTab), nPaint); rDocShell.PostPaint(ScRange(nStartX, nStartY, nTab, nEndX, nEndY, nTab), nPaint);
} }
// AdjustRowHeight( aLocalParam.nRow1, aLocalParam.nRow2, bPaint );
rDocShell.AdjustRowHeight( aLocalParam.nRow1, aLocalParam.nRow2, nTab ); rDocShell.AdjustRowHeight( aLocalParam.nRow1, aLocalParam.nRow2, nTab );
// #i59745# set collected drawing undo actions at sorting undo action // #i59745# set collected drawing undo actions at sorting undo action
......
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