summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2011-11-24 00:52:12 +0100
committerMichael Stahl <mstahl@redhat.com>2011-11-24 00:52:12 +0100
commit9a4dc4178c86f2639a23089acb6055cc0ca0321f (patch)
tree740c61500a7135c93bd9cb5ca5950a49efe5ba6b /sw
parentd43417b5474eab1a10c9529e3b02e930a53d4171 (diff)
SwIndex: cleanup: add Init method
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/index.hxx1
-rw-r--r--sw/source/core/bastyp/index.cxx48
2 files changed, 22 insertions, 27 deletions
diff --git a/sw/inc/index.hxx b/sw/inc/index.hxx
index b1f73f761578..cecb7bcdb0cc 100644
--- a/sw/inc/index.hxx
+++ b/sw/inc/index.hxx
@@ -61,6 +61,7 @@ private:
SwIndex * m_pPrev;
SwIndex& ChgValue( const SwIndex& rIdx, xub_StrLen nNewValue );
+ void Init(xub_StrLen const nIdx);
void Remove();
public:
diff --git a/sw/source/core/bastyp/index.cxx b/sw/source/core/bastyp/index.cxx
index 9461c4ee2f7d..e287c53ae92f 100644
--- a/sw/source/core/bastyp/index.cxx
+++ b/sw/source/core/bastyp/index.cxx
@@ -50,19 +50,7 @@ SwIndex::SwIndex(SwIndexReg *const pReg, xub_StrLen const nIdx)
m_nIndex = 0; // always 0 if no IndexReg
}
- if (!m_pIndexReg->m_pFirst || !m_pIndexReg->m_pLast) // first Index?
- {
- m_pIndexReg->m_pFirst = m_pIndexReg->m_pLast = this;
- }
- else if (nIdx > ((m_pIndexReg->m_pLast->m_nIndex
- - m_pIndexReg->m_pFirst->m_nIndex) / 2))
- {
- ChgValue( *m_pIndexReg->m_pLast, nIdx );
- }
- else
- {
- ChgValue( *m_pIndexReg->m_pFirst, nIdx );
- }
+ Init(m_nIndex);
}
SwIndex::SwIndex( const SwIndex& rIdx, xub_StrLen const nDiff )
@@ -82,6 +70,25 @@ SwIndex::SwIndex( const SwIndex& rIdx )
ChgValue( rIdx, rIdx.m_nIndex );
}
+void SwIndex::Init(xub_StrLen const nIdx)
+{
+ if (!m_pIndexReg->m_pFirst) // first Index?
+ {
+ OSL_ASSERT(!m_pIndexReg->m_pLast);
+ m_pIndexReg->m_pFirst = m_pIndexReg->m_pLast = this;
+ m_nIndex = nIdx;
+ }
+ else if (nIdx > ((m_pIndexReg->m_pLast->m_nIndex
+ - m_pIndexReg->m_pFirst->m_nIndex) / 2))
+ {
+ ChgValue( *m_pIndexReg->m_pLast, nIdx );
+ }
+ else
+ {
+ ChgValue( *m_pIndexReg->m_pFirst, nIdx );
+ }
+}
+
SwIndex& SwIndex::ChgValue( const SwIndex& rIdx, xub_StrLen nNewValue )
{
SwIndex* pFnd = const_cast<SwIndex*>(&rIdx);
@@ -209,20 +216,7 @@ SwIndex& SwIndex::Assign( SwIndexReg* pArr, xub_StrLen nIdx )
Remove();
m_pIndexReg = pArr;
m_pNext = m_pPrev = 0;
- if (!pArr->m_pFirst) // first index?
- {
- pArr->m_pFirst = pArr->m_pLast = this;
- m_nIndex = nIdx;
- }
- else if (pArr->m_pLast && (nIdx > ((pArr->m_pLast->m_nIndex
- - pArr->m_pFirst->m_nIndex) / 2)))
- {
- ChgValue( *pArr->m_pLast, nIdx );
- }
- else
- {
- ChgValue( *pArr->m_pFirst, nIdx );
- }
+ Init(nIdx);
}
else if (m_nIndex != nIdx)
ChgValue( *this, nIdx );