Update ooo320-m1
[ooovba.git] / applied_patches / 0191-calc-perf-sort.diff
blob84a9a82dec700c1821ccd5cd606e429bb515aeb5
1 diff --git sc/source/core/data/column.cxx sc/source/core/data/column.cxx
2 index b455d90..76ecf13 100644
3 --- sc/source/core/data/column.cxx
4 +++ sc/source/core/data/column.cxx
5 @@ -854,6 +854,10 @@ void lclTakeBroadcaster( ScBaseCell*& rpCell, SvtBroadcaster* pBC )
7 void ScColumn::SwapRow(SCROW nRow1, SCROW nRow2)
9 + // TODO: We probably don't need to broadcast value changes here since
10 + // deleting and inserting cells do it.
11 + bool bBroadcast = false;
13 /* Simple swap of cell pointers does not work if broadcasters exist (crash
14 if cell broadcasts directly or indirectly to itself). While swapping
15 the cells, broadcasters have to remain at old positions! */
16 @@ -912,10 +916,13 @@ void ScColumn::SwapRow(SCROW nRow1, SCROW nRow2)
17 pCell1->TakeBroadcaster( pBC2 );
18 pCell2->TakeBroadcaster( pBC1 );
20 - ScHint aHint1( SC_HINT_DATACHANGED, aPos1, pCell2 );
21 - pDocument->Broadcast( aHint1 );
22 - ScHint aHint2( SC_HINT_DATACHANGED, aPos2, pCell1 );
23 - pDocument->Broadcast( aHint2 );
24 + if (bBroadcast)
25 + {
26 + ScHint aHint1( SC_HINT_DATACHANGED, aPos1, pCell2 );
27 + pDocument->Broadcast( aHint1 );
28 + ScHint aHint2( SC_HINT_DATACHANGED, aPos2, pCell1 );
29 + pDocument->Broadcast( aHint2 );
30 + }
32 else
34 @@ -936,7 +943,8 @@ void ScColumn::SwapRow(SCROW nRow1, SCROW nRow2)
36 // insert ColEntry at new position
37 Insert( nRow2, pCell1 );
38 - pDocument->Broadcast( ScHint( SC_HINT_DATACHANGED, aPos1, pDummyCell ) );
39 + if (bBroadcast)
40 + pDocument->Broadcast( ScHint( SC_HINT_DATACHANGED, aPos1, pDummyCell ) );
43 return;
44 @@ -1021,10 +1029,13 @@ void ScColumn::SwapRow(SCROW nRow1, SCROW nRow2)
45 // #64122# Bei Formeln hinterher nochmal broadcasten, damit die Formel nicht in irgendwelchen
46 // FormulaTrack-Listen landet, ohne die Broadcaster beruecksichtigt zu haben
47 // (erst hier, wenn beide Zellen eingefuegt sind)
48 - if ( pBC1 && pFmlaCell2 )
49 - pDocument->Broadcast( ScHint( SC_HINT_DATACHANGED, aPos1, pNew1 ) );
50 - if ( pBC2 && pFmlaCell1 )
51 - pDocument->Broadcast( ScHint( SC_HINT_DATACHANGED, aPos2, pNew2 ) );
52 + if (bBroadcast)
53 + {
54 + if ( pBC1 && pFmlaCell2 )
55 + pDocument->Broadcast( ScHint( SC_HINT_DATACHANGED, aPos1, pNew1 ) );
56 + if ( pBC2 && pFmlaCell1 )
57 + pDocument->Broadcast( ScHint( SC_HINT_DATACHANGED, aPos2, pNew2 ) );
58 + }
62 diff --git sc/source/core/data/table3.cxx sc/source/core/data/table3.cxx
63 index c9f4a00..724ae58 100644
64 --- sc/source/core/data/table3.cxx
65 +++ sc/source/core/data/table3.cxx
66 @@ -348,17 +348,14 @@ void ScTable::SortReorder( ScSortInfoArray* pArray, ScProgress& rProgress )
68 BOOL bByRow = aSortParam.bByRow;
69 SCSIZE nCount = pArray->GetCount();
70 + SCCOLROW nStart = pArray->GetStart();
71 ScSortInfo** ppInfo = pArray->GetFirstArray();
72 - // hngngn.. Win16 legacy? Table has ULONG count but can only be initialized using USHORT :-/
73 - // FIXME: use std::vector instead, would be better anyway (type safe)
74 - USHORT nArghl = (nCount > USHRT_MAX ? USHRT_MAX : static_cast<USHORT>(nCount));
75 - Table aTable( nArghl );
76 + ::std::vector<ScSortInfo*> aTable(nCount);
77 SCSIZE nPos;
78 for ( nPos = 0; nPos < nCount; nPos++ )
79 - {
80 - aTable.Insert( ppInfo[nPos]->nOrg, (void*) ppInfo[nPos] );
81 - }
82 - SCCOLROW nDest = pArray->GetStart();
83 + aTable[ppInfo[nPos]->nOrg - nStart] = ppInfo[nPos];
85 + SCCOLROW nDest = nStart;
86 for ( nPos = 0; nPos < nCount; nPos++, nDest++ )
88 SCCOLROW nOrg = ppInfo[nPos]->nOrg;
89 @@ -371,9 +368,9 @@ void ScTable::SortReorder( ScSortInfoArray* pArray, ScProgress& rProgress )
90 // neue Position des weggeswapten eintragen
91 ScSortInfo* p = ppInfo[nPos];
92 p->nOrg = nDest;
93 - p = (ScSortInfo*) aTable.Replace( nDest, (void*) p );
94 + ::std::swap(p, aTable[nDest-nStart]);
95 p->nOrg = nOrg;
96 - p = (ScSortInfo*) aTable.Replace( nOrg, (void*) p );
97 + ::std::swap(p, aTable[nOrg-nStart]);
98 DBG_ASSERT( p == ppInfo[nPos], "SortReorder: nOrg MisMatch" );
100 rProgress.SetStateOnPercent( nPos );