Kaydet (Commit) 4623c603 authored tarafından Noel Grandin's avatar Noel Grandin Kaydeden (comit) Michael Stahl

sw: convert SwpHtStart SwpHtEnd to sorted_vector

Change-Id: I74696094ef066687582bd961d61a4877673016fd
üst 7ee95c52
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
#define _NDHINTS_HXX #define _NDHINTS_HXX
#include <svl/svarray.hxx>
#include <tools/mempool.hxx> #include <tools/mempool.hxx>
#include <o3tl/sorted_vector.hxx>
#include "swtypes.hxx" #include "swtypes.hxx"
...@@ -71,9 +71,17 @@ MakeRedlineTxtAttr( SwDoc & rDoc, SfxPoolItem& rAttr ); ...@@ -71,9 +71,17 @@ MakeRedlineTxtAttr( SwDoc & rDoc, SfxPoolItem& rAttr );
// Class SwpHtStart/End // Class SwpHtStart/End
struct CompareSwpHtStart
{
bool operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const;
};
class SwpHtStart : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtStart> {};
SV_DECL_PTRARR_SORT(SwpHtStart,SwTxtAttr*,1) struct CompareSwpHtEnd
SV_DECL_PTRARR_SORT(SwpHtEnd,SwTxtAttr*,1) {
bool operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const;
};
class SwpHtEnd : public o3tl::sorted_vector<SwTxtAttr*, CompareSwpHtEnd> {};
// Class SwpHintsArr // Class SwpHintsArr
...@@ -102,18 +110,17 @@ public: ...@@ -102,18 +110,17 @@ public:
inline SwTxtAttr * GetEnd ( const sal_uInt16 nPos ) inline SwTxtAttr * GetEnd ( const sal_uInt16 nPos )
{ return m_HintEnds [nPos]; } { return m_HintEnds [nPos]; }
inline sal_uInt16 GetEndCount() const { return m_HintEnds .Count(); } inline sal_uInt16 GetEndCount() const { return m_HintEnds .size(); }
inline sal_uInt16 GetStartCount() const { return m_HintStarts.Count(); } inline sal_uInt16 GetStartCount() const { return m_HintStarts.size(); }
inline sal_uInt16 GetStartOf( const SwTxtAttr *pHt ) const; inline sal_uInt16 GetStartOf( const SwTxtAttr *pHt ) const;
inline sal_uInt16 GetPos( const SwTxtAttr *pHt ) const sal_uInt16 GetPos( const SwTxtAttr *pHt ) const;
{ return m_HintStarts.GetPos( pHt ); }
inline SwTxtAttr * GetTextHint( const sal_uInt16 nIdx ) inline SwTxtAttr * GetTextHint( const sal_uInt16 nIdx )
{ return GetStart(nIdx); } { return GetStart(nIdx); }
inline const SwTxtAttr * operator[]( const sal_uInt16 nIdx ) const inline const SwTxtAttr * operator[]( const sal_uInt16 nIdx ) const
{ return m_HintStarts[nIdx]; } { return m_HintStarts[nIdx]; }
inline sal_uInt16 Count() const { return m_HintStarts.Count(); } inline sal_uInt16 Count() const { return m_HintStarts.size(); }
#ifdef DBG_UTIL #ifdef DBG_UTIL
bool Check() const; bool Check() const;
...@@ -205,12 +212,12 @@ SvStream &operator<<(SvStream &aS, const SwpHints &rHints); //$ ostream ...@@ -205,12 +212,12 @@ SvStream &operator<<(SvStream &aS, const SwpHints &rHints); //$ ostream
inline sal_uInt16 SwpHintsArray::GetStartOf( const SwTxtAttr *pHt ) const inline sal_uInt16 SwpHintsArray::GetStartOf( const SwTxtAttr *pHt ) const
{ {
sal_uInt16 nPos; SwpHtStart::const_iterator it = m_HintStarts.find( (SwTxtAttr*)pHt );
if ( !m_HintStarts.Seek_Entry( pHt, &nPos ) ) if ( it == m_HintStarts.end() )
{ {
nPos = USHRT_MAX; return USHRT_MAX;
} }
return nPos; return it - m_HintStarts.begin();
} }
inline SwTxtAttr *SwpHintsArray::Cut( const sal_uInt16 nPosInStart ) inline SwTxtAttr *SwpHintsArray::Cut( const sal_uInt16 nPosInStart )
......
...@@ -36,9 +36,6 @@ ...@@ -36,9 +36,6 @@
#endif #endif
_SV_IMPL_SORTAR_ALG( SwpHtStart, SwTxtAttr* )
_SV_IMPL_SORTAR_ALG( SwpHtEnd, SwTxtAttr* )
inline void DumpHints(const SwpHtStart &, const SwpHtEnd &) { } inline void DumpHints(const SwpHtStart &, const SwpHtEnd &) { }
/************************************************************************* /*************************************************************************
...@@ -125,76 +122,14 @@ static sal_Bool lcl_IsLessEnd( const SwTxtAttr &rHt1, const SwTxtAttr &rHt2 ) ...@@ -125,76 +122,14 @@ static sal_Bool lcl_IsLessEnd( const SwTxtAttr &rHt1, const SwTxtAttr &rHt2 )
return ( nHt1 < nHt2 ); return ( nHt1 < nHt2 );
} }
/************************************************************************* bool CompareSwpHtStart::operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const
* SwpHtStart::Seek_Entry()
*************************************************************************/
sal_Bool SwpHtStart::Seek_Entry( const SwTxtAttr *pElement, sal_uInt16 *pPos ) const
{ {
sal_uInt16 nOben = Count(), nMitte, nUnten = 0; return lcl_IsLessStart( *lhs, *rhs );
if( nOben > 0 )
{
nOben--;
while( nUnten <= nOben )
{
nMitte = nUnten + ( nOben - nUnten ) / 2;
const SwTxtAttr *pMitte = (*this)[nMitte];
if( IsEqual( *pMitte, *pElement ) )
{
*pPos = nMitte;
return sal_True;
}
else
if( lcl_IsLessStart( *pMitte, *pElement ) )
nUnten = nMitte + 1;
else
if( nMitte == 0 )
{
*pPos = nUnten;
return sal_False;
}
else
nOben = nMitte - 1;
}
}
*pPos = nUnten;
return sal_False;
} }
/************************************************************************* bool CompareSwpHtEnd::operator()(SwTxtAttr* const lhs, SwTxtAttr* const rhs) const
* SwpHtEnd::Seek_Entry()
*************************************************************************/
sal_Bool SwpHtEnd::Seek_Entry( const SwTxtAttr *pElement, sal_uInt16 *pPos ) const
{ {
sal_uInt16 nOben = Count(), nMitte, nUnten = 0; return lcl_IsLessEnd( *lhs, *rhs );
if( nOben > 0 )
{
nOben--;
while( nUnten <= nOben )
{
nMitte = nUnten + ( nOben - nUnten ) / 2;
const SwTxtAttr *pMitte = (*this)[nMitte];
if( IsEqual( *pMitte, *pElement ) )
{
*pPos = nMitte;
return sal_True;
}
else
if( lcl_IsLessEnd( *pMitte, *pElement ) )
nUnten = nMitte + 1;
else
if( nMitte == 0 )
{
*pPos = nUnten;
return sal_False;
}
else
nOben = nMitte - 1;
}
}
*pPos = nUnten;
return sal_False;
} }
/************************************************************************* /*************************************************************************
...@@ -205,27 +140,32 @@ void SwpHintsArray::Insert( const SwTxtAttr *pHt ) ...@@ -205,27 +140,32 @@ void SwpHintsArray::Insert( const SwTxtAttr *pHt )
{ {
Resort(); Resort();
#if OSL_DEBUG_LEVEL > 0 #if OSL_DEBUG_LEVEL > 0
sal_uInt16 nPos; OSL_ENSURE(m_HintStarts.find( (SwTxtAttr*)pHt ) == m_HintStarts.end(),
OSL_ENSURE(!m_HintStarts.Seek_Entry( pHt, &nPos ),
"Insert: hint already in HtStart"); "Insert: hint already in HtStart");
OSL_ENSURE(!m_HintEnds.Seek_Entry( pHt, &nPos ), OSL_ENSURE(m_HintEnds.find( (SwTxtAttr*)pHt ) == m_HintEnds.end(),
"Insert: hint already in HtEnd"); "Insert: hint already in HtEnd");
#endif #endif
m_HintStarts.Insert( pHt ); m_HintStarts.insert( (SwTxtAttr*)pHt );
m_HintEnds.Insert( pHt ); m_HintEnds.insert( (SwTxtAttr*)pHt );
} }
void SwpHintsArray::DeleteAtPos( const sal_uInt16 nPos ) void SwpHintsArray::DeleteAtPos( const sal_uInt16 nPos )
{ {
// optimization: nPos is the position in the Starts array // optimization: nPos is the position in the Starts array
const SwTxtAttr *pHt = m_HintStarts[ nPos ]; SwTxtAttr *pHt = m_HintStarts[ nPos ];
m_HintStarts.Remove( nPos ); m_HintStarts.erase( m_HintStarts.begin() + nPos );
Resort(); Resort();
sal_uInt16 nEndPos; m_HintEnds.erase( pHt );
m_HintEnds.Seek_Entry( pHt, &nEndPos ); }
m_HintEnds.Remove( nEndPos );
sal_uInt16 SwpHintsArray::GetPos( const SwTxtAttr *pHt ) const
{
SwpHtStart::const_iterator it = m_HintStarts.find( (SwTxtAttr*)pHt );
if( it == m_HintStarts.end() )
return USHRT_MAX;
return it - m_HintStarts.begin();
} }
#ifdef DBG_UTIL #ifdef DBG_UTIL
...@@ -246,7 +186,7 @@ void SwpHintsArray::DeleteAtPos( const sal_uInt16 nPos ) ...@@ -246,7 +186,7 @@ void SwpHintsArray::DeleteAtPos( const sal_uInt16 nPos )
bool SwpHintsArray::Check() const bool SwpHintsArray::Check() const
{ {
// 1) gleiche Anzahl in beiden Arrays // 1) gleiche Anzahl in beiden Arrays
CHECK_ERR( m_HintStarts.Count() == m_HintEnds.Count(), CHECK_ERR( m_HintStarts.size() == m_HintEnds.size(),
"HintsCheck: wrong sizes" ); "HintsCheck: wrong sizes" );
xub_StrLen nLastStart = 0; xub_StrLen nLastStart = 0;
xub_StrLen nLastEnd = 0; xub_StrLen nLastEnd = 0;
...@@ -294,13 +234,13 @@ bool SwpHintsArray::Check() const ...@@ -294,13 +234,13 @@ bool SwpHintsArray::Check() const
// --- Ueberkreuzungen --- // --- Ueberkreuzungen ---
// 5) gleiche Pointer in beiden Arrays // 5) gleiche Pointer in beiden Arrays
if( !m_HintStarts.Seek_Entry( pHt, &nIdx ) ) if( m_HintStarts.find( (SwTxtAttr*)pHt ) == m_HintStarts.end() )
nIdx = STRING_LEN; nIdx = STRING_LEN;
CHECK_ERR( STRING_LEN != nIdx, "HintsCheck: no GetStartOf" ); CHECK_ERR( STRING_LEN != nIdx, "HintsCheck: no GetStartOf" );
// 6) gleiche Pointer in beiden Arrays // 6) gleiche Pointer in beiden Arrays
if( !m_HintEnds.Seek_Entry( pHt, &nIdx ) ) if( m_HintEnds.find( (SwTxtAttr*)pHt ) == m_HintEnds.end() )
nIdx = STRING_LEN; nIdx = STRING_LEN;
CHECK_ERR( STRING_LEN != nIdx, "HintsCheck: no GetEndOf" ); CHECK_ERR( STRING_LEN != nIdx, "HintsCheck: no GetEndOf" );
...@@ -386,13 +326,13 @@ bool SwpHintsArray::Resort() ...@@ -386,13 +326,13 @@ bool SwpHintsArray::Resort()
const SwTxtAttr *pLast = 0; const SwTxtAttr *pLast = 0;
sal_uInt16 i; sal_uInt16 i;
for ( i = 0; i < m_HintStarts.Count(); ++i ) for ( i = 0; i < m_HintStarts.size(); ++i )
{ {
const SwTxtAttr *pHt = m_HintStarts[i]; SwTxtAttr *pHt = m_HintStarts[i];
if( pLast && !lcl_IsLessStart( *pLast, *pHt ) ) if( pLast && !lcl_IsLessStart( *pLast, *pHt ) )
{ {
m_HintStarts.Remove( i ); m_HintStarts.erase( m_HintStarts.begin() + i );
m_HintStarts.Insert( pHt ); m_HintStarts.insert( pHt );
pHt = m_HintStarts[i]; pHt = m_HintStarts[i];
if ( pHt != pLast ) if ( pHt != pLast )
--i; --i;
...@@ -402,13 +342,13 @@ bool SwpHintsArray::Resort() ...@@ -402,13 +342,13 @@ bool SwpHintsArray::Resort()
} }
pLast = 0; pLast = 0;
for ( i = 0; i < m_HintEnds.Count(); ++i ) for ( i = 0; i < m_HintEnds.size(); ++i )
{ {
const SwTxtAttr *pHt = m_HintEnds[i]; SwTxtAttr *pHt = m_HintEnds[i];
if( pLast && !lcl_IsLessEnd( *pLast, *pHt ) ) if( pLast && !lcl_IsLessEnd( *pLast, *pHt ) )
{ {
m_HintEnds.Remove( i ); m_HintEnds.erase( m_HintEnds.begin() + i );
m_HintEnds.Insert( pHt ); m_HintEnds.insert( pHt );
pHt = m_HintEnds[i]; // normalerweise == pLast pHt = m_HintEnds[i]; // normalerweise == pLast
// Wenn die Unordnung etwas groesser ist (24200), // Wenn die Unordnung etwas groesser ist (24200),
// muessen wir Position i erneut vergleichen. // muessen wir Position i erneut vergleichen.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment