summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaarten Bosmans <mkbosmans@gmail.com>2016-10-04 23:02:40 +0200
committerEike Rathke <erack@redhat.com>2016-10-20 22:53:47 +0000
commit580cddc6260dedfcc48f291f424e65525c0428b1 (patch)
tree996064d138c925cea7d02f979aa58b1ec7802de4
parentacfe9c225a8905f9742a9d9494ee242a45a15d50 (diff)
Convert ScConsData into using std::vector
This simplifies the ScReferenceList handling significantly. Change-Id: I2204a4d56c98fdf7dcd593901dcf5cc0f7c52a62 Reviewed-on: https://gerrit.libreoffice.org/29530 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Eike Rathke <erack@redhat.com>
-rw-r--r--sc/inc/consoli.hxx34
-rw-r--r--sc/source/core/tool/consoli.cxx60
2 files changed, 17 insertions, 77 deletions
diff --git a/sc/inc/consoli.hxx b/sc/inc/consoli.hxx
index 9d994710b7b2..784f511fa7b6 100644
--- a/sc/inc/consoli.hxx
+++ b/sc/inc/consoli.hxx
@@ -25,33 +25,6 @@
class ScDocument;
-struct ScReferenceEntry // without constructor !
-{
- SCCOL nCol;
- SCROW nRow;
- SCTAB nTab;
-};
-
-//! Use delta value for data?
-
-class ScReferenceList // without constructor !
-{
-private:
- SCSIZE nCount;
- SCSIZE nFullSize; // incl. fill entries
- ScReferenceEntry* pData;
-
-public:
- void Init() { nCount=0; nFullSize=0; pData=nullptr; }
- void Clear() { delete[] pData; }
-
- SCSIZE GetCount() { return nCount; }
- const ScReferenceEntry& GetEntry( SCSIZE nPos ) { return pData[nPos]; }
- void SetFullSize( SCSIZE nNew ) { nFullSize = nNew; }
-
- void AddEntry( SCCOL nCol, SCROW nRow, SCTAB nTab );
-};
-
// Sequence:
// 1) create ScConsData
// 2) Parameter (Size/Flags)
@@ -66,6 +39,13 @@ public:
class ScConsData
{
private:
+ struct ScReferenceEntry // without constructor !
+ {
+ SCCOL nCol;
+ SCROW nRow;
+ SCTAB nTab;
+ };
+ typedef std::vector<ScReferenceEntry> ScReferenceList;
ScSubTotalFunc eFunction;
bool bReference;
bool bColByName;
diff --git a/sc/source/core/tool/consoli.cxx b/sc/source/core/tool/consoli.cxx
index 651e14ed0551..67801532e8eb 100644
--- a/sc/source/core/tool/consoli.cxx
+++ b/sc/source/core/tool/consoli.cxx
@@ -47,29 +47,6 @@ static const OpCode eOpCodeTable[] = { // order as for enum ScSubTotalFunc
ocVar,
ocVarP };
-void ScReferenceList::AddEntry( SCCOL nCol, SCROW nRow, SCTAB nTab )
-{
- ScReferenceEntry* pOldData = pData;
- pData = new ScReferenceEntry[ nFullSize+1 ];
- if (pOldData)
- {
- memcpy( pData, pOldData, nCount * sizeof(ScReferenceEntry) );
- delete[] pOldData;
- }
- while (nCount < nFullSize)
- {
- pData[nCount].nCol = SC_CONS_NOTFOUND;
- pData[nCount].nRow = SC_CONS_NOTFOUND;
- pData[nCount].nTab = SC_CONS_NOTFOUND;
- ++nCount;
- }
- pData[nCount].nCol = nCol;
- pData[nCount].nRow = nRow;
- pData[nCount].nTab = nTab;
- ++nCount;
- nFullSize = nCount;
-}
-
template< typename T >
static void lcl_AddString( ::std::vector<OUString>& rData, T& nCount, const OUString& rInsert )
{
@@ -116,9 +93,6 @@ void ScConsData::DeleteData()
{
for (SCSIZE i=0; i<nColCount; i++)
{
- for (SCSIZE j=0; j<nRowCount; j++)
- if (ppUsed[i][j])
- ppRefs[i][j].Clear();
delete[] ppRefs[i];
}
delete[] ppRefs;
@@ -128,7 +102,7 @@ void ScConsData::DeleteData()
DELETEARR( ppCount, nColCount );
DELETEARR( ppSum, nColCount );
DELETEARR( ppSumSqr,nColCount );
- DELETEARR( ppUsed, nColCount ); // only after ppRefs !!!
+ DELETEARR( ppUsed, nColCount );
DELETEARR( ppTitlePos, nRowCount );
::std::vector<OUString>().swap( maColHeaders);
::std::vector<OUString>().swap( maRowHeaders);
@@ -281,17 +255,12 @@ void ScConsData::AddName( const OUString& rName )
SCSIZE nMax = 0;
for (nArrX=0; nArrX<nColCount; nArrX++)
- if (ppUsed[nArrX][nArrY])
- nMax = std::max( nMax, ppRefs[nArrX][nArrY].GetCount() );
+ nMax = std::max( nMax, ppRefs[nArrX][nArrY].size() );
for (nArrX=0; nArrX<nColCount; nArrX++)
{
- if (!ppUsed[nArrX][nArrY])
- {
- ppUsed[nArrX][nArrY] = true;
- ppRefs[nArrX][nArrY].Init();
- }
- ppRefs[nArrX][nArrY].SetFullSize(nMax);
+ ppUsed[nArrX][nArrY] = true;
+ ppRefs[nArrX][nArrY].resize( nMax, { SC_CONS_NOTFOUND, SC_CONS_NOTFOUND, SC_CONS_NOTFOUND });
}
// store positions
@@ -564,14 +533,8 @@ void ScConsData::AddData( ScDocument* pSrcDoc, SCTAB nTab,
{
if (bReference)
{
- if (ppUsed[nArrX][nArrY])
- ppRefs[nArrX][nArrY].AddEntry( nCol, nRow, nTab );
- else
- {
- ppUsed[nArrX][nArrY] = true;
- ppRefs[nArrX][nArrY].Init();
- ppRefs[nArrX][nArrY].AddEntry( nCol, nRow, nTab );
- }
+ ppUsed[nArrX][nArrY] = true;
+ ppRefs[nArrX][nArrY].push_back( { nCol, nRow, nTab } );
}
else
{
@@ -608,8 +571,7 @@ SCROW ScConsData::GetInsertCount() const
{
SCSIZE nNeeded = 0;
for (nArrX=0; nArrX<nColCount; nArrX++)
- if (ppUsed[nArrX][nArrY])
- nNeeded = std::max( nNeeded, ppRefs[nArrX][nArrY].GetCount() );
+ nNeeded = std::max( nNeeded, ppRefs[nArrX][nArrY].size() );
nInsert += nNeeded;
}
@@ -687,8 +649,7 @@ void ScConsData::OutputToDocument( ScDocument* pDestDoc, SCCOL nCol, SCROW nRow,
{
SCSIZE nNeeded = 0;
for (nArrX=0; nArrX<nColCount; nArrX++)
- if (ppUsed[nArrX][nArrY])
- nNeeded = std::max( nNeeded, ppRefs[nArrX][nArrY].GetCount() );
+ nNeeded = std::max( nNeeded, ppRefs[nArrX][nArrY].size() );
if (nNeeded)
{
@@ -697,13 +658,12 @@ void ScConsData::OutputToDocument( ScDocument* pDestDoc, SCCOL nCol, SCROW nRow,
for (nArrX=0; nArrX<nColCount; nArrX++)
if (ppUsed[nArrX][nArrY])
{
- ScReferenceList& rList = ppRefs[nArrX][nArrY];
- SCSIZE nCount = rList.GetCount();
+ SCSIZE nCount = ppRefs[nArrX][nArrY].size();
if (nCount)
{
for (SCSIZE nPos=0; nPos<nCount; nPos++)
{
- ScReferenceEntry aRef = rList.GetEntry(nPos);
+ ScReferenceEntry aRef = ppRefs[nArrX][nArrY][nPos];
if (aRef.nTab != SC_CONS_NOTFOUND)
{
// insert reference (absolute, 3d)