[Libreoffice-commits] core.git: sc/inc sc/source
Noel Grandin
noel.grandin at collabora.co.uk
Wed Mar 14 06:19:05 UTC 2018
sc/inc/rangelst.hxx | 3
sc/source/core/tool/rangelst.cxx | 168 +++++++++++++++++---------------------
sc/source/ui/miscdlgs/crnrdlg.cxx | 18 ++--
3 files changed, 88 insertions(+), 101 deletions(-)
New commits:
commit bb787e7b45efb5e25b4b6d57a42efa916510b5f5
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Tue Mar 13 17:35:21 2018 +0200
modernize ScRangePairList::CreateNameSortedArray
we have this STL thingy now, pretty cool
Change-Id: Id96010dda59736bd0c143312424018b6ea5621f1
Reviewed-on: https://gerrit.libreoffice.org/51230
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/sc/inc/rangelst.hxx b/sc/inc/rangelst.hxx
index d78c7054499d..e137613df857 100644
--- a/sc/inc/rangelst.hxx
+++ b/sc/inc/rangelst.hxx
@@ -139,7 +139,8 @@ public:
void DeleteOnTab( SCTAB nTab );
ScRangePair* Find( const ScAddress& ) const;
ScRangePair* Find( const ScRange& ) const;
- ScRangePair** CreateNameSortedArray( size_t& nCount, ScDocument* ) const;
+ std::vector<ScRangePair*>
+ CreateNameSortedArray( ScDocument* ) const;
void Remove(size_t nPos);
void Remove(const ScRangePair* pAdr);
diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx
index 84c6764ab79a..62a083bcab96 100644
--- a/sc/source/core/tool/rangelst.cxx
+++ b/sc/source/core/tool/rangelst.cxx
@@ -1323,82 +1323,81 @@ ScRangePairList* ScRangePairList::Clone() const
return pNew;
}
-struct ScRangePairNameSort
+class ScRangePairList_sortNameCompare
{
- ScRangePair* pPair;
- ScDocument* pDoc;
-};
+public:
+ ScRangePairList_sortNameCompare(ScDocument *pDoc) : mpDoc(pDoc) {}
-extern "C"
-int ScRangePairList_QsortNameCompare( const void* p1, const void* p2 )
-{
- const ScRangePairNameSort* ps1 = static_cast<const ScRangePairNameSort*>(p1);
- const ScRangePairNameSort* ps2 = static_cast<const ScRangePairNameSort*>(p2);
- const ScAddress& rStartPos1 = ps1->pPair->GetRange(0).aStart;
- const ScAddress& rStartPos2 = ps2->pPair->GetRange(0).aStart;
- OUString aStr1, aStr2;
- sal_Int32 nComp;
- if ( rStartPos1.Tab() == rStartPos2.Tab() )
- nComp = 0;
- else
- {
- ps1->pDoc->GetName( rStartPos1.Tab(), aStr1 );
- ps2->pDoc->GetName( rStartPos2.Tab(), aStr2 );
- nComp = ScGlobal::GetCollator()->compareString( aStr1, aStr2 );
- }
- if (nComp < 0)
+ bool operator()( const ScRangePair *ps1, const ScRangePair* ps2 ) const
{
- return -1;
- }
- else if (nComp > 0)
- {
- return 1;
- }
+ const ScAddress& rStartPos1 = ps1->GetRange(0).aStart;
+ const ScAddress& rStartPos2 = ps2->GetRange(0).aStart;
+ OUString aStr1, aStr2;
+ sal_Int32 nComp;
+ if ( rStartPos1.Tab() == rStartPos2.Tab() )
+ nComp = 0;
+ else
+ {
+ mpDoc->GetName( rStartPos1.Tab(), aStr1 );
+ mpDoc->GetName( rStartPos2.Tab(), aStr2 );
+ nComp = ScGlobal::GetCollator()->compareString( aStr1, aStr2 );
+ }
+ if (nComp < 0)
+ {
+ return true; // -1;
+ }
+ else if (nComp > 0)
+ {
+ return false; // 1;
+ }
- // equal tabs
- if ( rStartPos1.Col() < rStartPos2.Col() )
- return -1;
- if ( rStartPos1.Col() > rStartPos2.Col() )
- return 1;
- // equal cols
- if ( rStartPos1.Row() < rStartPos2.Row() )
- return -1;
- if ( rStartPos1.Row() > rStartPos2.Row() )
- return 1;
-
- // first corner equal, second corner
- const ScAddress& rEndPos1 = ps1->pPair->GetRange(0).aEnd;
- const ScAddress& rEndPos2 = ps2->pPair->GetRange(0).aEnd;
- if ( rEndPos1.Tab() == rEndPos2.Tab() )
- nComp = 0;
- else
- {
- ps1->pDoc->GetName( rEndPos1.Tab(), aStr1 );
- ps2->pDoc->GetName( rEndPos2.Tab(), aStr2 );
- nComp = ScGlobal::GetCollator()->compareString( aStr1, aStr2 );
- }
- if (nComp < 0)
- {
- return -1;
- }
- else if (nComp > 0)
- {
- return 1;
- }
+ // equal tabs
+ if ( rStartPos1.Col() < rStartPos2.Col() )
+ return true; // -1;
+ if ( rStartPos1.Col() > rStartPos2.Col() )
+ return false; // 1;
+ // equal cols
+ if ( rStartPos1.Row() < rStartPos2.Row() )
+ return true; // -1;
+ if ( rStartPos1.Row() > rStartPos2.Row() )
+ return false; // 1;
+
+ // first corner equal, second corner
+ const ScAddress& rEndPos1 = ps1->GetRange(0).aEnd;
+ const ScAddress& rEndPos2 = ps2->GetRange(0).aEnd;
+ if ( rEndPos1.Tab() == rEndPos2.Tab() )
+ nComp = 0;
+ else
+ {
+ mpDoc->GetName( rEndPos1.Tab(), aStr1 );
+ mpDoc->GetName( rEndPos2.Tab(), aStr2 );
+ nComp = ScGlobal::GetCollator()->compareString( aStr1, aStr2 );
+ }
+ if (nComp < 0)
+ {
+ return true; // -1;
+ }
+ else if (nComp > 0)
+ {
+ return false; // 1;
+ }
- // equal tabs
- if ( rEndPos1.Col() < rEndPos2.Col() )
- return -1;
- if ( rEndPos1.Col() > rEndPos2.Col() )
- return 1;
- // equal cols
- if ( rEndPos1.Row() < rEndPos2.Row() )
- return -1;
- if ( rEndPos1.Row() > rEndPos2.Row() )
- return 1;
-
- return 0;
-}
+ // equal tabs
+ if ( rEndPos1.Col() < rEndPos2.Col() )
+ return true; // -1;
+ if ( rEndPos1.Col() > rEndPos2.Col() )
+ return false; // 1;
+ // equal cols
+ if ( rEndPos1.Row() < rEndPos2.Row() )
+ return true; // -1;
+ if ( rEndPos1.Row() > rEndPos2.Row() )
+ return false; // 1;
+
+ return false;
+ }
+private:
+ ScDocument *mpDoc;
+};
void ScRangePairList::Join( const ScRangePair& r, bool bIsInList )
{
@@ -1524,28 +1523,13 @@ Label_RangePair_Join:
Append( r );
}
-ScRangePair** ScRangePairList::CreateNameSortedArray( size_t& nListCount,
- ScDocument* pDoc ) const
+std::vector<ScRangePair*> ScRangePairList::CreateNameSortedArray( ScDocument* pDoc ) const
{
- nListCount = maPairs.size();
- OSL_ENSURE( nListCount * sizeof(ScRangePairNameSort) <= size_t(~0x1F),
- "ScRangePairList::CreateNameSortedArray nListCount * sizeof(ScRangePairNameSort) > (size_t)~0x1F" );
- ScRangePairNameSort* pSortArray = reinterpret_cast<ScRangePairNameSort*>(
- new sal_uInt8 [ nListCount * sizeof(ScRangePairNameSort) ]);
- sal_uLong j;
- for ( j=0; j < nListCount; j++ )
- {
- pSortArray[j].pPair = maPairs[ j ];
- pSortArray[j].pDoc = pDoc;
- }
- qsort( static_cast<void*>(pSortArray), nListCount, sizeof(ScRangePairNameSort), &ScRangePairList_QsortNameCompare );
- // move ScRangePair pointer up
- ScRangePair** ppSortArray = reinterpret_cast<ScRangePair**>(pSortArray);
- for ( j=0; j < nListCount; j++ )
- {
- ppSortArray[j] = pSortArray[j].pPair;
- }
- return ppSortArray;
+ std::vector<ScRangePair*> aSortedVec(maPairs);
+
+ std::sort( aSortedVec.begin(), aSortedVec.end(), ScRangePairList_sortNameCompare(pDoc) );
+
+ return aSortedVec;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/miscdlgs/crnrdlg.cxx b/sc/source/ui/miscdlgs/crnrdlg.cxx
index 1c464898b75b..31df267e218f 100644
--- a/sc/source/ui/miscdlgs/crnrdlg.cxx
+++ b/sc/source/ui/miscdlgs/crnrdlg.cxx
@@ -391,15 +391,16 @@ void ScColRowNameRangesDlg::UpdateNames()
pLbRange->SetEntryData( nPos, reinterpret_cast<void*>(nEntryDataDelim) );
if ( (nCount = xColNameRanges->size()) > 0 )
{
- std::unique_ptr<ScRangePair*[]> ppSortArray(xColNameRanges->CreateNameSortedArray(
- nCount, pDoc ));
+ std::vector<ScRangePair*> aSortArray(xColNameRanges->CreateNameSortedArray(
+ pDoc ));
+ nCount = aSortArray.size();
for ( j=0; j < nCount; j++ )
{
- const ScRange aRange(ppSortArray[j]->GetRange(0));
+ const ScRange aRange(aSortArray[j]->GetRange(0));
aString = aRange.Format(ScRefFlags::RANGE_ABS_3D, pDoc, aDetails);
//@008 get range parameters from document
- ppSortArray[j]->GetRange(0).GetVars( nCol1, nRow1, nTab1,
+ aSortArray[j]->GetRange(0).GetVars( nCol1, nRow1, nTab1,
nCol2, nRow2, nTab2 );
SCCOL q=nCol1+3;
if(q>nCol2) q=nCol2;
@@ -434,15 +435,16 @@ void ScColRowNameRangesDlg::UpdateNames()
pLbRange->SetEntryData( nPos, reinterpret_cast<void*>(nEntryDataDelim) );
if ( (nCount = xRowNameRanges->size()) > 0 )
{
- std::unique_ptr<ScRangePair*[]> ppSortArray(xRowNameRanges->CreateNameSortedArray(
- nCount, pDoc ));
+ std::vector<ScRangePair*> aSortArray(xRowNameRanges->CreateNameSortedArray(
+ pDoc ));
+ nCount = aSortArray.size();
for ( j=0; j < nCount; j++ )
{
- const ScRange aRange(ppSortArray[j]->GetRange(0));
+ const ScRange aRange(aSortArray[j]->GetRange(0));
aString = aRange.Format(ScRefFlags::RANGE_ABS_3D, pDoc, aDetails);
//@008 Build string for rows below
- ppSortArray[j]->GetRange(0).GetVars( nCol1, nRow1, nTab1,
+ aSortArray[j]->GetRange(0).GetVars( nCol1, nRow1, nTab1,
nCol2, nRow2, nTab2 );
SCROW q=nRow1+3;
if(q>nRow2) q=nRow2;
More information about the Libreoffice-commits
mailing list