[Libreoffice-commits] .: Branch 'libreoffice-4-0' - o3tl/inc sw/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Fri Jan 11 02:40:56 PST 2013
o3tl/inc/o3tl/sorted_vector.hxx | 12 ++++++++-
sw/source/core/txtnode/ndhints.cxx | 48 +++++--------------------------------
2 files changed, 18 insertions(+), 42 deletions(-)
New commits:
commit cdd0555aefa0a01d0d90fed8640811c5601f314e
Author: Michael Stahl <mstahl at redhat.com>
Date: Fri Jan 11 11:04:31 2013 +0100
fdo#58793: re-implement SwpHintsArray::Resort():
The previous implementation uses sorted_vector::insert, which relies on
the array already being sorted.
Change-Id: I4a2e49e7d8fcfd934f8990be61f83d00d1a09ddd
(cherry picked from commit c59355e936446fe55960209e543b072acb6b2170)
Signed-off-by: Thorsten Behrens <tbehrens at suse.com>
diff --git a/o3tl/inc/o3tl/sorted_vector.hxx b/o3tl/inc/o3tl/sorted_vector.hxx
index d8bceb7..3028f03 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 20f1de5..a15bd12 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?
}
More information about the Libreoffice-commits
mailing list