diff options
-rw-r--r-- | o3tl/inc/o3tl/sorted_vector.hxx | 12 | ||||
-rw-r--r-- | sw/source/core/txtnode/ndhints.cxx | 48 |
2 files changed, 18 insertions, 42 deletions
diff --git a/o3tl/inc/o3tl/sorted_vector.hxx b/o3tl/inc/o3tl/sorted_vector.hxx index d8bceb72e39d..3028f03e1a02 100644 --- a/o3tl/inc/o3tl/sorted_vector.hxx +++ b/o3tl/inc/o3tl/sorted_vector.hxx @@ -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> diff --git a/sw/source/core/txtnode/ndhints.cxx b/sw/source/core/txtnode/ndhints.cxx index aa0a36d622fd..a627c1dc4304 100644 --- a/sw/source/core/txtnode/ndhints.cxx +++ b/sw/source/core/txtnode/ndhints.cxx @@ -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? } |