diff -uNr old/sc/inc/table.hxx new/sc/inc/table.hxx --- old/sc/inc/table.hxx 2008-02-15 16:55:50.000000000 +0800 +++ new/sc/inc/table.hxx 2008-09-08 16:46:04.000000000 +0800 @@ -685,6 +685,7 @@ short Compare( ScSortInfoArray*, SCCOLROW nIndex1, SCCOLROW nIndex2); ScSortInfoArray* CreateSortInfoArray( SCCOLROW nInd1, SCCOLROW nInd2 ); void QuickSort( ScSortInfoArray*, SCsCOLROW nLo, SCsCOLROW nHi); + void SortPosition( ScSortInfoArray* pArray, SCsCOLROW nLow, SCsCOLROW nHigh ); void SortReorder( ScSortInfoArray*, ScProgress& ); BOOL CreateExcelQuery(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, ScQueryParam& rQueryParam); diff -uNr old/sc/source/core/data/table3.cxx new/sc/source/core/data/table3.cxx --- old/sc/source/core/data/table3.cxx 2008-02-15 16:55:52.000000000 +0800 +++ new/sc/source/core/data/table3.cxx 2008-09-08 16:41:00.000000000 +0800 @@ -355,6 +355,61 @@ return nRes; } +void lcl_QuickSort( ScSortInfoArray* pArray, SCsCOLROW nStart, SCsCOLROW nEnd ) +{ + SCsCOLROW ni = nStart; + SCsCOLROW nj = nEnd; + ScSortInfo** ppInfo = pArray->GetFirstArray(); + SCCOLROW nDest = pArray->GetStart(); + do + { + while ((ni <= nEnd) && ppInfo[ni-nDest]->nOrg < ppInfo[nStart-nDest]->nOrg ) + ni++; + while ((nj >= nStart) && ppInfo[nj-nDest]->nOrg > ppInfo[nStart-nDest]->nOrg ) + nj--; + if (ni <= nj) + { + if (ni != nj) + pArray->Swap( ni, nj ); + ni++; + nj--; + } + } while (ni < nj); + if ((nj - nStart) < (nEnd - ni)) + { + if (nStart < nj) + lcl_QuickSort(pArray, nStart, nj); + if (ni < nEnd) + lcl_QuickSort(pArray, ni, nEnd); + } + else + { + if (ni < nEnd) + lcl_QuickSort(pArray, ni, nEnd); + if (nStart < nj) + lcl_QuickSort(pArray, nStart, nj); + } +} + +void ScTable::SortPosition( ScSortInfoArray* pArray, SCsCOLROW nLow, SCsCOLROW nHigh ) +{ + SCsCOLROW i; + SCsCOLROW aStart = nLow; + for( i=aStart+1; i<=nHigh; i++ ) + { + if( Compare( pArray, aStart, i ) != 0 ) + { + if( aStart != i-1 ) + lcl_QuickSort( pArray, aStart, i-1 ); + aStart = i; + } + } + if( Compare( pArray, aStart, nHigh ) == 0 ) + { + lcl_QuickSort( pArray, aStart, nHigh ); + } +} + short ScTable::Compare( ScSortInfoArray* pArray, SCCOLROW nIndex1, SCCOLROW nIndex2 ) { short nRes; @@ -532,6 +587,7 @@ if ( nLastRow - nRow1 > 255 ) DecoladeRow( pArray, nRow1, nLastRow ); QuickSort( pArray, nRow1, nLastRow ); + SortPosition( pArray, nRow1, nLastRow ); SortReorder( pArray, aProgress ); delete pArray; } @@ -551,6 +607,7 @@ ScGlobal::GetRscString(STR_PROGRESS_SORTING), nLastCol - nCol1 ); ScSortInfoArray* pArray = CreateSortInfoArray( nCol1, nLastCol ); QuickSort( pArray, nCol1, nLastCol ); + SortPosition( pArray, nCol1, nLastCol); SortReorder( pArray, aProgress ); delete pArray; }