fdo#58793: re-implement SwpHintsArray::Resort():

The previous implementation uses sorted_vector::insert, which relies on
the array already being sorted.

Change-Id: I4a2e49e7d8fcfd934f8990be61f83d00d1a09ddd
This commit is contained in:
Michael Stahl
2013-01-11 11:04:31 +01:00
parent 689d9af3e3
commit c59355e936
2 changed files with 18 additions and 42 deletions

View File

@@ -155,6 +155,16 @@ public:
clear();
}
// fdo#58793: some existing code in Writer (SwpHintsArray)
// routinely modifies the members of the vector in a way that
// violates the sort order, and then re-sorts the array.
// This is a kludge to enable that code to work.
// If you are calling this function, you are Doing It Wrong!
void Resort()
{
std::stable_sort(begin_nonconst(), end_nonconst(), Compare());
}
private:
typename base_t::iterator begin_nonconst() { return base_t::begin(); }
@@ -191,7 +201,7 @@ struct find_unique
}
};
/** the elments are partially ordered by Compare,
/** the elements are partially ordered by Compare,
2 elements are allowed if they are not the same element (pointer equal)
*/
template<class Value, class Compare>

View File

@@ -310,50 +310,16 @@ bool SwpHintsArray::Check() const
* SwpHintsArray::Resort()
*************************************************************************/
// Resort() wird vor jedem Insert und Delete gerufen.
// Wenn Textmasse geloescht wird, so werden die Indizes in
// ndtxt.cxx angepasst. Leider erfolgt noch keine Neusortierung
// auf gleichen Positionen.
// Resort() is called before every Insert and Delete.
// Various SwTxtNode methods modify hints in a way that violates the
// sort order of the m_HintStarts, m_HintEnds arrays, so this method is needed
// to restore the order.
bool SwpHintsArray::Resort()
{
bool bResort = false;
const SwTxtAttr *pLast = 0;
sal_uInt16 i;
for ( i = 0; i < m_HintStarts.size(); ++i )
{
SwTxtAttr *pHt = m_HintStarts[i];
if( pLast && !lcl_IsLessStart( *pLast, *pHt ) )
{
m_HintStarts.erase( m_HintStarts.begin() + i );
m_HintStarts.insert( pHt );
pHt = m_HintStarts[i];
if ( pHt != pLast )
--i;
bResort = true;
}
pLast = pHt;
}
pLast = 0;
for ( i = 0; i < m_HintEnds.size(); ++i )
{
SwTxtAttr *pHt = m_HintEnds[i];
if( pLast && !lcl_IsLessEnd( *pLast, *pHt ) )
{
m_HintEnds.erase( m_HintEnds.begin() + i );
m_HintEnds.insert( pHt );
pHt = m_HintEnds[i]; // normalerweise == pLast
// Wenn die Unordnung etwas groesser ist (24200),
// muessen wir Position i erneut vergleichen.
if ( pLast != pHt )
--i;
bResort = true;
}
pLast = pHt;
}
return bResort;
m_HintStarts.Resort();
m_HintEnds.Resort();
return false; // TODO: probably unused return value?
}