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

Slightly more efficient assign().

The old code performed array lookup twice; once for the cell type and twice
for the value fetch.  The new code does lookup only once.

Change-Id: Ic6f5927b5536a73cb0a5c00a6c3a12ff0cd1f1e0
üst 9b689d6e
......@@ -442,6 +442,8 @@ public:
ScFormulaVectorState GetFormulaVectorState( SCROW nRow ) const;
ScRefCellValue GetRefCellValue( SCROW );
void SetNumberFormat( SCROW nRow, sal_uInt32 nNumberFormat );
private:
......
......@@ -144,6 +144,7 @@ class SvtListener;
class ScNotes;
class ScEditDataArray;
class EditTextObject;
class ScRefCellValue;
namespace com { namespace sun { namespace star {
namespace lang {
......@@ -217,6 +218,7 @@ friend class ScDocRowHeightUpdater;
friend class ScColumnTextWidthIterator;
friend class ScFormulaCell;
friend class ScTable;
friend class ScRefCellValue;
typedef ::std::vector<ScTable*> TableContainer;
private:
......@@ -1976,6 +1978,8 @@ private: // CLOOK-Impl-methods
void PutCell( const ScAddress&, ScBaseCell* pCell, bool bForceTab = false );
void PutCell(SCCOL nCol, SCROW nRow, SCTAB nTab, ScBaseCell* pCell, sal_uLong nFormatIndex, bool bForceTab = false );
ScRefCellValue GetRefCellValue( const ScAddress& rPos );
std::map< SCTAB, ScSortParam > mSheetSortParams;
};
......
......@@ -818,6 +818,8 @@ public:
ScFormulaVectorState GetFormulaVectorState( SCCOL nCol, SCROW nRow ) const;
ScRefCellValue GetRefCellValue( SCCOL nCol, SCROW nRow );
private:
void FillSeries( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
sal_uLong nFillCount, FillDir eFillDir, FillCmd eFillCmd,
......
......@@ -188,20 +188,24 @@ void ScCellValue::assign( const ScDocument& rDoc, const ScAddress& rPos )
{
clear();
meType = rDoc.GetCellType(rPos);
ScRefCellValue aRefVal;
aRefVal.assign(const_cast<ScDocument&>(rDoc), rPos);
meType = aRefVal.meType;
switch (meType)
{
case CELLTYPE_STRING:
mpString = new OUString(rDoc.GetString(rPos));
mpString = new OUString(*aRefVal.mpString);
break;
case CELLTYPE_EDIT:
mpEditText = rDoc.GetEditText(rPos)->Clone();
if (aRefVal.mpEditText)
mpEditText = aRefVal.mpEditText->Clone();
break;
case CELLTYPE_VALUE:
mfValue = rDoc.GetValue(rPos);
mfValue = aRefVal.mfValue;
break;
case CELLTYPE_FORMULA:
mpFormula = rDoc.GetFormulaCell(rPos)->Clone();
mpFormula = aRefVal.mpFormula->Clone();
break;
default:
meType = CELLTYPE_NONE; // reset to empty.
......@@ -398,26 +402,7 @@ void ScRefCellValue::clear()
void ScRefCellValue::assign( ScDocument& rDoc, const ScAddress& rPos )
{
clear();
meType = rDoc.GetCellType(rPos);
switch (meType)
{
case CELLTYPE_STRING:
mpString = rDoc.GetStringCell(rPos);
break;
case CELLTYPE_EDIT:
mpEditText = rDoc.GetEditText(rPos);
break;
case CELLTYPE_VALUE:
mfValue = rDoc.GetValue(rPos);
break;
case CELLTYPE_FORMULA:
mpFormula = rDoc.GetFormulaCell(rPos);
break;
default:
meType = CELLTYPE_NONE; // reset to empty.
}
*this = rDoc.GetRefCellValue(rPos);
}
void ScRefCellValue::assign( ScBaseCell& rCell )
......
......@@ -1543,6 +1543,36 @@ ScFormulaVectorState ScColumn::GetFormulaVectorState( SCROW nRow ) const
return pCell ? pCell->GetVectorState() : FormulaVectorUnknown;
}
ScRefCellValue ScColumn::GetRefCellValue( SCROW nRow )
{
ScRefCellValue aCell; // start empty
SCSIZE nIndex;
if (!Search(nRow, nIndex))
return aCell;
ScBaseCell* pCell = maItems[nIndex].pCell;
aCell.meType = pCell->GetCellType();
switch (aCell.meType)
{
case CELLTYPE_STRING:
aCell.mpString = static_cast<const ScStringCell*>(pCell)->GetStringPtr();
break;
case CELLTYPE_EDIT:
aCell.mpEditText = static_cast<const ScEditCell*>(pCell)->GetData();
break;
case CELLTYPE_VALUE:
aCell.mfValue = static_cast<const ScValueCell*>(pCell)->GetValue();
break;
case CELLTYPE_FORMULA:
aCell.mpFormula = static_cast<ScFormulaCell*>(pCell);
break;
default:
aCell.meType = CELLTYPE_NONE; // reset to empty.
}
return aCell;
}
void ScColumn::SetNumberFormat( SCROW nRow, sal_uInt32 nNumberFormat )
{
short eOldType = pDocument->GetFormatTable()->GetType(
......
......@@ -599,6 +599,13 @@ void ScDocument::PutCell( SCCOL nCol, SCROW nRow, SCTAB nTab,
}
}
ScRefCellValue ScDocument::GetRefCellValue( const ScAddress& rPos )
{
if (!TableExists(rPos.Tab()))
return ScRefCellValue(); // empty
return maTabs[rPos.Tab()]->GetRefCellValue(rPos.Col(), rPos.Row());
}
bool ScDocument::GetPrintArea( SCTAB nTab, SCCOL& rEndCol, SCROW& rEndRow,
bool bNotes ) const
......
......@@ -45,6 +45,7 @@
#include "colorscale.hxx"
#include "conditio.hxx"
#include "globalnames.hxx"
#include "cellvalue.hxx"
#include <vector>
......@@ -2112,6 +2113,14 @@ ScFormulaVectorState ScTable::GetFormulaVectorState( SCCOL nCol, SCROW nRow ) co
return aCol[nCol].GetFormulaVectorState(nRow);
}
ScRefCellValue ScTable::GetRefCellValue( SCCOL nCol, SCROW nRow )
{
if (!ValidColRow(nCol, nRow))
return ScRefCellValue();
return aCol[nCol].GetRefCellValue(nRow);
}
void ScTable::DeleteConditionalFormat( sal_uLong nIndex )
{
mpCondFormatList->erase(nIndex);
......
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