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:
@@ -155,6 +155,16 @@ public:
|
|||||||
clear();
|
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:
|
private:
|
||||||
|
|
||||||
typename base_t::iterator begin_nonconst() { return base_t::begin(); }
|
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)
|
2 elements are allowed if they are not the same element (pointer equal)
|
||||||
*/
|
*/
|
||||||
template<class Value, class Compare>
|
template<class Value, class Compare>
|
||||||
|
@@ -310,50 +310,16 @@ bool SwpHintsArray::Check() const
|
|||||||
* SwpHintsArray::Resort()
|
* SwpHintsArray::Resort()
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
// Resort() wird vor jedem Insert und Delete gerufen.
|
// Resort() is called before every Insert and Delete.
|
||||||
// Wenn Textmasse geloescht wird, so werden die Indizes in
|
// Various SwTxtNode methods modify hints in a way that violates the
|
||||||
// ndtxt.cxx angepasst. Leider erfolgt noch keine Neusortierung
|
// sort order of the m_HintStarts, m_HintEnds arrays, so this method is needed
|
||||||
// auf gleichen Positionen.
|
// to restore the order.
|
||||||
|
|
||||||
bool SwpHintsArray::Resort()
|
bool SwpHintsArray::Resort()
|
||||||
{
|
{
|
||||||
bool bResort = false;
|
m_HintStarts.Resort();
|
||||||
const SwTxtAttr *pLast = 0;
|
m_HintEnds.Resort();
|
||||||
sal_uInt16 i;
|
return false; // TODO: probably unused return value?
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user