[Libreoffice-commits] core.git: 9 commits - sw/inc sw/Library_sw.mk sw/source

Bjoern Michaelsen bjoern.michaelsen at canonical.com
Mon Dec 22 19:03:58 PST 2014


 sw/Library_sw.mk                   |    1 
 sw/inc/ndarr.hxx                   |   11 +-
 sw/inc/ndindex.hxx                 |  121 ++++++++++++++++++++++++++------
 sw/inc/ring.hxx                    |    2 
 sw/source/core/docnode/ndindex.cxx |  138 -------------------------------------
 sw/source/core/docnode/nodes.cxx   |   64 +----------------
 6 files changed, 108 insertions(+), 229 deletions(-)

New commits:
commit a6c0583675b6fe4210ae8249728fe5d4df125f5c
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Mon Dec 22 00:03:44 2014 +0100

    remove duplicated code
    
    Change-Id: Id306d1dc75ef9d5ec5ec2e48be318e0632ea2377

diff --git a/sw/inc/ndindex.hxx b/sw/inc/ndindex.hxx
index b6e7ca2..2663fcb 100644
--- a/sw/inc/ndindex.hxx
+++ b/sw/inc/ndindex.hxx
@@ -261,14 +261,7 @@ inline SwNodeIndex& SwNodeIndex::operator=( sal_uLong nWert )
 
 SwNodeIndex& SwNodeIndex::operator=( const SwNodeIndex& rIdx )
 {
-    if( &pNd->GetNodes() != &rIdx.pNd->GetNodes() )
-    {
-        DeRegisterIndex( pNd->GetNodes() );
-        pNd = rIdx.pNd;
-        RegisterIndex( pNd->GetNodes() );
-    }
-    else
-        pNd = rIdx.pNd;
+    *this = *(rIdx.pNd);
     return *this;
 }
 
@@ -287,27 +280,13 @@ SwNodeIndex& SwNodeIndex::operator=( const SwNode& rNd )
 
 SwNodeIndex& SwNodeIndex::Assign( SwNodes& rNds, sal_uLong nIdx )
 {
-    if( &pNd->GetNodes() != &rNds )
-    {
-        DeRegisterIndex( pNd->GetNodes() );
-        pNd = rNds[ nIdx ];
-        RegisterIndex( pNd->GetNodes() );
-    }
-    else
-        pNd = rNds[ nIdx ];
+    *this = *rNds[ nIdx ];
     return *this;
 }
 
 SwNodeIndex& SwNodeIndex::Assign( const SwNode& rNd, long nOffset )
 {
-    if( &pNd->GetNodes() != &rNd.GetNodes() )
-    {
-        DeRegisterIndex( pNd->GetNodes() );
-        pNd = const_cast<SwNode*>(&rNd);
-        RegisterIndex( pNd->GetNodes() );
-    }
-    else
-        pNd = const_cast<SwNode*>(&rNd);
+    *this = rNd;
 
     if( nOffset )
         pNd = pNd->GetNodes()[ pNd->GetIndex() + nOffset ];
commit 583c949612ac40c21b02886f4d37a45212946138
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Sun Dec 21 23:05:47 2014 +0100

    c-style cast to const_cast
    
    Change-Id: Ie5d8483305f4ef2d76c291fcb8c707a69ba9cf52

diff --git a/sw/inc/ndindex.hxx b/sw/inc/ndindex.hxx
index f31c851..b6e7ca2 100644
--- a/sw/inc/ndindex.hxx
+++ b/sw/inc/ndindex.hxx
@@ -75,7 +75,7 @@ public:
         if( nDiff )
             pNd = rNd.GetNodes()[ rNd.GetIndex() + nDiff ];
         else
-            pNd = (SwNode*)&rNd;
+            pNd = const_cast<SwNode*>(&rNd);
         RegisterIndex( pNd->GetNodes() );
     }
 
@@ -277,11 +277,11 @@ SwNodeIndex& SwNodeIndex::operator=( const SwNode& rNd )
     if( &pNd->GetNodes() != &rNd.GetNodes() )
     {
         DeRegisterIndex( pNd->GetNodes() );
-        pNd = (SwNode*)&rNd;
+        pNd = const_cast<SwNode*>(&rNd);
         RegisterIndex( pNd->GetNodes() );
     }
     else
-        pNd = (SwNode*)&rNd;
+        pNd = const_cast<SwNode*>(&rNd);
     return *this;
 }
 
@@ -303,11 +303,11 @@ SwNodeIndex& SwNodeIndex::Assign( const SwNode& rNd, long nOffset )
     if( &pNd->GetNodes() != &rNd.GetNodes() )
     {
         DeRegisterIndex( pNd->GetNodes() );
-        pNd = (SwNode*)&rNd;
+        pNd = const_cast<SwNode*>(&rNd);
         RegisterIndex( pNd->GetNodes() );
     }
     else
-        pNd = (SwNode*)&rNd;
+        pNd = const_cast<SwNode*>(&rNd);
 
     if( nOffset )
         pNd = pNd->GetNodes()[ pNd->GetIndex() + nOffset ];
commit 310eb66522ff30492e8b3cd86dbafaeb52cdff90
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Sat Dec 20 16:55:24 2014 +0100

    inline stream operator and remove object
    
    Change-Id: I9df9a56eca662c6adf0a2cf4ef25a917da8dc609

diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk
index f9a4e03..2af35f2 100644
--- a/sw/Library_sw.mk
+++ b/sw/Library_sw.mk
@@ -224,7 +224,6 @@ $(eval $(call gb_Library_add_exception_objects,sw,\
     sw/source/core/docnode/cancellablejob \
     sw/source/core/docnode/finalthreadmanager \
     sw/source/core/docnode/ndcopy \
-    sw/source/core/docnode/ndindex \
     sw/source/core/docnode/ndnotxt \
     sw/source/core/docnode/ndnum \
     sw/source/core/docnode/ndsect \
diff --git a/sw/inc/ndindex.hxx b/sw/inc/ndindex.hxx
index 72f28de..f31c851 100644
--- a/sw/inc/ndindex.hxx
+++ b/sw/inc/ndindex.hxx
@@ -124,7 +124,10 @@ public:
     SwNode& GetNode() const { return *pNd; }
 };
 
-std::ostream &operator <<(std::ostream& s, const SwNodeIndex& index);
+inline std::ostream &operator <<(std::ostream& s, const SwNodeIndex& index)
+{
+    return s << "SwNodeIndex (node " << index.GetIndex() << ")";
+};
 
 // SwRange
 
diff --git a/sw/source/core/docnode/ndindex.cxx b/sw/source/core/docnode/ndindex.cxx
deleted file mode 100644
index eed9080..0000000
--- a/sw/source/core/docnode/ndindex.cxx
+++ /dev/null
@@ -1,28 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include "ndindex.hxx"
-
-
-std::ostream &operator <<(std::ostream& s, const SwNodeIndex& index)
-{
-    return s << "SwNodeIndex (node " << index.GetIndex() << ")";
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 96c7fff36eb2ed21bba604b3c0c376559e14539c
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Sat Dec 20 16:53:29 2014 +0100

    inline Assign
    
    Change-Id: Ibeb8d7b8e83d432a502707f83a8fde7900596aec

diff --git a/sw/inc/ndindex.hxx b/sw/inc/ndindex.hxx
index 51ae682..72f28de 100644
--- a/sw/inc/ndindex.hxx
+++ b/sw/inc/ndindex.hxx
@@ -114,8 +114,8 @@ public:
     inline sal_uLong GetIndex() const;
 
     // Enables assignments without creation of a temporary object.
-    SwNodeIndex& Assign( SwNodes& rNds, sal_uLong );
-    SwNodeIndex& Assign( const SwNode& rNd, long nOffset = 0 );
+    inline SwNodeIndex& Assign( SwNodes& rNds, sal_uLong );
+    inline SwNodeIndex& Assign( const SwNode& rNd, long nOffset = 0 );
 
     // Gets pointer on NodesArray.
     inline const SwNodes& GetNodes() const;
@@ -282,6 +282,36 @@ SwNodeIndex& SwNodeIndex::operator=( const SwNode& rNd )
     return *this;
 }
 
+SwNodeIndex& SwNodeIndex::Assign( SwNodes& rNds, sal_uLong nIdx )
+{
+    if( &pNd->GetNodes() != &rNds )
+    {
+        DeRegisterIndex( pNd->GetNodes() );
+        pNd = rNds[ nIdx ];
+        RegisterIndex( pNd->GetNodes() );
+    }
+    else
+        pNd = rNds[ nIdx ];
+    return *this;
+}
+
+SwNodeIndex& SwNodeIndex::Assign( const SwNode& rNd, long nOffset )
+{
+    if( &pNd->GetNodes() != &rNd.GetNodes() )
+    {
+        DeRegisterIndex( pNd->GetNodes() );
+        pNd = (SwNode*)&rNd;
+        RegisterIndex( pNd->GetNodes() );
+    }
+    else
+        pNd = (SwNode*)&rNd;
+
+    if( nOffset )
+        pNd = pNd->GetNodes()[ pNd->GetIndex() + nOffset ];
+
+    return *this;
+}
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/docnode/ndindex.cxx b/sw/source/core/docnode/ndindex.cxx
index 4f563a2..eed9080 100644
--- a/sw/source/core/docnode/ndindex.cxx
+++ b/sw/source/core/docnode/ndindex.cxx
@@ -19,61 +19,6 @@
 
 #include "ndindex.hxx"
 
-SwNodeIndex& SwNodeIndex::operator=( const SwNodeIndex& rIdx )
-{
-    if( &pNd->GetNodes() != &rIdx.pNd->GetNodes() )
-    {
-        DeRegisterIndex( pNd->GetNodes() );
-        pNd = rIdx.pNd;
-        RegisterIndex( pNd->GetNodes() );
-    }
-    else
-        pNd = rIdx.pNd;
-    return *this;
-}
-
-SwNodeIndex& SwNodeIndex::operator=( const SwNode& rNd )
-{
-    if( &pNd->GetNodes() != &rNd.GetNodes() )
-    {
-        DeRegisterIndex( pNd->GetNodes() );
-        pNd = (SwNode*)&rNd;
-        RegisterIndex( pNd->GetNodes() );
-    }
-    else
-        pNd = (SwNode*)&rNd;
-    return *this;
-}
-
-SwNodeIndex& SwNodeIndex::Assign( SwNodes& rNds, sal_uLong nIdx )
-{
-    if( &pNd->GetNodes() != &rNds )
-    {
-        DeRegisterIndex( pNd->GetNodes() );
-        pNd = rNds[ nIdx ];
-        RegisterIndex( pNd->GetNodes() );
-    }
-    else
-        pNd = rNds[ nIdx ];
-    return *this;
-}
-
-SwNodeIndex& SwNodeIndex::Assign( const SwNode& rNd, long nOffset )
-{
-    if( &pNd->GetNodes() != &rNd.GetNodes() )
-    {
-        DeRegisterIndex( pNd->GetNodes() );
-        pNd = (SwNode*)&rNd;
-        RegisterIndex( pNd->GetNodes() );
-    }
-    else
-        pNd = (SwNode*)&rNd;
-
-    if( nOffset )
-        pNd = pNd->GetNodes()[ pNd->GetIndex() + nOffset ];
-
-    return *this;
-}
 
 std::ostream &operator <<(std::ostream& s, const SwNodeIndex& index)
 {
commit eaf3774752869e0322a340d5be4ab1b328f3632a
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Sat Dec 20 16:51:25 2014 +0100

    inline operator=
    
    Change-Id: I2a74b9821072025cdf374d5e157411136e08ebec

diff --git a/sw/inc/ndindex.hxx b/sw/inc/ndindex.hxx
index ba3dc47..51ae682 100644
--- a/sw/inc/ndindex.hxx
+++ b/sw/inc/ndindex.hxx
@@ -107,8 +107,8 @@ public:
     inline bool operator!=( sal_uLong nWert ) const;
 
     inline SwNodeIndex& operator=( sal_uLong );
-           SwNodeIndex& operator=( const SwNodeIndex& );
-           SwNodeIndex& operator=( const SwNode& );
+    inline SwNodeIndex& operator=( const SwNodeIndex& );
+    inline SwNodeIndex& operator=( const SwNode& );
 
     // Return value of index as sal_uLong.
     inline sal_uLong GetIndex() const;
@@ -256,6 +256,32 @@ inline SwNodeIndex& SwNodeIndex::operator=( sal_uLong nWert )
     return *this;
 }
 
+SwNodeIndex& SwNodeIndex::operator=( const SwNodeIndex& rIdx )
+{
+    if( &pNd->GetNodes() != &rIdx.pNd->GetNodes() )
+    {
+        DeRegisterIndex( pNd->GetNodes() );
+        pNd = rIdx.pNd;
+        RegisterIndex( pNd->GetNodes() );
+    }
+    else
+        pNd = rIdx.pNd;
+    return *this;
+}
+
+SwNodeIndex& SwNodeIndex::operator=( const SwNode& rNd )
+{
+    if( &pNd->GetNodes() != &rNd.GetNodes() )
+    {
+        DeRegisterIndex( pNd->GetNodes() );
+        pNd = (SwNode*)&rNd;
+        RegisterIndex( pNd->GetNodes() );
+    }
+    else
+        pNd = (SwNode*)&rNd;
+    return *this;
+}
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit b74fc841445c92ce458619bbf73a5c6e08e2b640
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Sat Dec 20 16:49:36 2014 +0100

    remove Remove()
    
    Change-Id: Ic1854d5e8cd76825290a3af94d8884e93dd7f0da

diff --git a/sw/inc/ndindex.hxx b/sw/inc/ndindex.hxx
index 254dd29..ba3dc47 100644
--- a/sw/inc/ndindex.hxx
+++ b/sw/inc/ndindex.hxx
@@ -36,9 +36,6 @@ class SW_DLLPUBLIC SwNodeIndex SAL_FINAL : public sw::Ring<SwNodeIndex>
 {
     SwNode* pNd;
 
-    void Remove()
-        { DeRegisterIndex( pNd->GetNodes() ); };
-
     // These are not allowed!
     SwNodeIndex( SwNodes& rNds, sal_uInt16 nIdx );
     SwNodeIndex( SwNodes& rNds, int nIdx );
@@ -82,7 +79,8 @@ public:
         RegisterIndex( pNd->GetNodes() );
     }
 
-    ~SwNodeIndex() { Remove(); }
+    ~SwNodeIndex()
+        { DeRegisterIndex( pNd->GetNodes() ); };
 
     inline sal_uLong operator++();
     inline sal_uLong operator--();
commit d5d46849714d4749467b409f6e9c7758b80e1b63
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Sat Dec 20 16:48:18 2014 +0100

    Make SwNodeIndex constructors inline
    
    Change-Id: Ib29bcd5e2028c4e644621af4294c193f5b0aa14e

diff --git a/sw/inc/ndindex.hxx b/sw/inc/ndindex.hxx
index 1bc358f..254dd29 100644
--- a/sw/inc/ndindex.hxx
+++ b/sw/inc/ndindex.hxx
@@ -36,7 +36,8 @@ class SW_DLLPUBLIC SwNodeIndex SAL_FINAL : public sw::Ring<SwNodeIndex>
 {
     SwNode* pNd;
 
-    void Remove();
+    void Remove()
+        { DeRegisterIndex( pNd->GetNodes() ); };
 
     // These are not allowed!
     SwNodeIndex( SwNodes& rNds, sal_uInt16 nIdx );
@@ -57,9 +58,30 @@ class SW_DLLPUBLIC SwNodeIndex SAL_FINAL : public sw::Ring<SwNodeIndex>
     }
 
 public:
-    SwNodeIndex( SwNodes& rNds, sal_uLong nIdx = 0 );
-    SwNodeIndex( const SwNodeIndex &, long nDiff = 0 );
-    SwNodeIndex( const SwNode&, long nDiff = 0 );
+    SwNodeIndex( SwNodes& rNds, sal_uLong nIdx = 0 )
+        : pNd( rNds[ nIdx ] )
+    {
+        RegisterIndex( rNds );
+    };
+    SwNodeIndex( const SwNodeIndex& rIdx, long nDiff = 0 )
+        : sw::Ring<SwNodeIndex>()
+    {
+        if( nDiff )
+            pNd = rIdx.GetNodes()[ rIdx.GetIndex() + nDiff ];
+        else
+            pNd = rIdx.pNd;
+        RegisterIndex( pNd->GetNodes() );
+    }
+
+    SwNodeIndex( const SwNode& rNd, long nDiff = 0 )
+    {
+        if( nDiff )
+            pNd = rNd.GetNodes()[ rNd.GetIndex() + nDiff ];
+        else
+            pNd = (SwNode*)&rNd;
+        RegisterIndex( pNd->GetNodes() );
+    }
+
     ~SwNodeIndex() { Remove(); }
 
     inline sal_uLong operator++();
@@ -114,14 +136,18 @@ public:
     SwNodeIndex aStart;
     SwNodeIndex aEnd;
 
-    SwNodeRange( const SwNodeIndex &rS, const SwNodeIndex &rE );
-    SwNodeRange( const SwNodeRange &rRange );
+    SwNodeRange( const SwNodeIndex &rS, const SwNodeIndex &rE )
+        : aStart( rS ), aEnd( rE ) {};
+    SwNodeRange( const SwNodeRange &rRange )
+        : aStart( rRange.aStart ), aEnd( rRange.aEnd ) {};
+
+    SwNodeRange( SwNodes& rNds, sal_uLong nSttIdx = 0, sal_uLong nEndIdx = 0 )
+        : aStart( rNds, nSttIdx ), aEnd( rNds, nEndIdx ) {};
 
-    SwNodeRange( SwNodes& rArr, sal_uLong nSttIdx = 0, sal_uLong nEndIdx = 0 );
-    SwNodeRange( const SwNodeIndex& rS, long nSttDiff,
-                 const SwNodeIndex& rE, long nEndDiff = 0 );
-    SwNodeRange( const SwNode& rS, long nSttDiff,
-                 const SwNode& rE, long nEndDiff = 0 );
+    SwNodeRange( const SwNodeIndex& rS, long nSttDiff, const SwNodeIndex& rE, long nEndDiff = 0 )
+        : aStart( rS, nSttDiff ), aEnd( rE, nEndDiff ) {};
+    SwNodeRange( const SwNode& rS, long nSttDiff, const SwNode& rE, long nEndDiff = 0 )
+        : aStart( rS, nSttDiff ), aEnd( rE, nEndDiff ) {};
 };
 
 // For inlines node.hxx is needed which in turn needs this one.
diff --git a/sw/source/core/docnode/ndindex.cxx b/sw/source/core/docnode/ndindex.cxx
index f70b92e..4f563a2 100644
--- a/sw/source/core/docnode/ndindex.cxx
+++ b/sw/source/core/docnode/ndindex.cxx
@@ -19,60 +19,6 @@
 
 #include "ndindex.hxx"
 
-SwNodeRange::SwNodeRange( const SwNodeIndex &rS, const SwNodeIndex &rE )
-    : aStart( rS ), aEnd( rE )
-{}
-
-SwNodeRange::SwNodeRange( const SwNodeRange &rRange )
-    : aStart( rRange.aStart ), aEnd( rRange.aEnd )
-{}
-
-SwNodeRange::SwNodeRange( SwNodes& rNds, sal_uLong nSttIdx, sal_uLong nEndIdx )
-    : aStart( rNds, nSttIdx ), aEnd( rNds, nEndIdx )
-{}
-
-SwNodeRange::SwNodeRange( const SwNodeIndex& rS, long nSttDiff,
-                          const SwNodeIndex& rE, long nEndDiff )
-    : aStart( rS, nSttDiff ), aEnd( rE, nEndDiff )
-{}
-
-SwNodeRange::SwNodeRange( const SwNode& rS, long nSttDiff,
-                          const SwNode& rE, long nEndDiff )
-    : aStart( rS, nSttDiff ), aEnd( rE, nEndDiff )
-{}
-
-SwNodeIndex::SwNodeIndex( SwNodes& rNds, sal_uLong nIdx )
-    : pNd( rNds[ nIdx ] )
-{
-    RegisterIndex( rNds );
-}
-
-SwNodeIndex::SwNodeIndex( const SwNodeIndex& rIdx, long nDiff )
-    : sw::Ring<SwNodeIndex>()
-{
-    if( nDiff )
-        pNd = rIdx.GetNodes()[ rIdx.GetIndex() + nDiff ];
-    else
-        pNd = rIdx.pNd;
-
-    RegisterIndex( pNd->GetNodes() );
-}
-
-SwNodeIndex::SwNodeIndex( const SwNode& rNd, long nDiff )
-{
-    if( nDiff )
-        pNd = rNd.GetNodes()[ rNd.GetIndex() + nDiff ];
-    else
-        pNd = (SwNode*)&rNd;
-
-    RegisterIndex( pNd->GetNodes() );
-}
-
-void SwNodeIndex::Remove()
-{
-    DeRegisterIndex( pNd->GetNodes() );
-}
-
 SwNodeIndex& SwNodeIndex::operator=( const SwNodeIndex& rIdx )
 {
     if( &pNd->GetNodes() != &rIdx.pNd->GetNodes() )
commit 7a6639fc9d0bfc3481744a6de648ccbf754a109d
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Sat Dec 20 16:29:47 2014 +0100

    Move Register/DeRegister functions to SwNodeIndex
    
    - allows more inlining
    - allows removing another friendliness
    - belongs there anyway
    
    Change-Id: I5d0d24f60caa06533efcd3f41f313fe55dd365e1

diff --git a/sw/inc/ndarr.hxx b/sw/inc/ndarr.hxx
index c7979da..a4c83c6 100644
--- a/sw/inc/ndarr.hxx
+++ b/sw/inc/ndarr.hxx
@@ -96,6 +96,7 @@ class SW_DLLPUBLIC SwNodes
     friend class ::sw::DocumentContentOperationsManager;
 
     SwNodeIndex* vIndices; ///< ring of all indices on nodes.
+    void RemoveNode( sal_uLong nDelPos, sal_uLong nLen, bool bDel );
 
     void InsertNode( const SwNodePtr pNode,
                      const SwNodeIndex& rPos );
@@ -115,11 +116,6 @@ class SW_DLLPUBLIC SwNodes
     bool bInDelUpdOutl : 1;         ///< Flag for updating of Outline.
     bool bInDelUpdNum : 1;          ///< Flag for updating of Outline.
 
-    /// For administering indices.
-    void RegisterIndex( SwNodeIndex& rIdx );
-    void DeRegisterIndex( SwNodeIndex& rIdx );
-    void RemoveNode( sal_uLong nDelPos, sal_uLong nLen, bool bDel );
-
     // Actions on the nodes.
     void SectionUpDown( const SwNodeIndex & aStart, const SwNodeIndex & aEnd );
     void DelNodes( const SwNodeIndex& rStart, sal_uLong nCnt = 1 );
@@ -337,6 +333,7 @@ public:
     void dumpAsXml( xmlTextWriterPtr writer = NULL ) const;
 };
 
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/inc/ndindex.hxx b/sw/inc/ndindex.hxx
index e0439cc..1bc358f 100644
--- a/sw/inc/ndindex.hxx
+++ b/sw/inc/ndindex.hxx
@@ -26,6 +26,7 @@
 
 #include <node.hxx>
 #include <ring.hxx>
+#include <ndarr.hxx>
 
 class SwNode;
 class SwNodes;
@@ -33,7 +34,6 @@ class SwNodes;
 /// Marks a node in the document model.
 class SW_DLLPUBLIC SwNodeIndex SAL_FINAL : public sw::Ring<SwNodeIndex>
 {
-    friend void SwNodes::DeRegisterIndex( SwNodeIndex& );
     SwNode* pNd;
 
     void Remove();
@@ -41,6 +41,20 @@ class SW_DLLPUBLIC SwNodeIndex SAL_FINAL : public sw::Ring<SwNodeIndex>
     // These are not allowed!
     SwNodeIndex( SwNodes& rNds, sal_uInt16 nIdx );
     SwNodeIndex( SwNodes& rNds, int nIdx );
+    void RegisterIndex( SwNodes& rNodes )
+    {
+        if(!rNodes.vIndices)
+            rNodes.vIndices = this;
+        MoveTo(rNodes.vIndices);
+    }
+    void DeRegisterIndex( SwNodes& rNodes )
+    {
+        if(rNodes.vIndices == this)
+            rNodes.vIndices = GetNextInRing();
+        MoveTo(nullptr);
+        if(rNodes.vIndices == this)
+            rNodes.vIndices = nullptr;
+    }
 
 public:
     SwNodeIndex( SwNodes& rNds, sal_uLong nIdx = 0 );
diff --git a/sw/source/core/docnode/ndindex.cxx b/sw/source/core/docnode/ndindex.cxx
index 3656000..f70b92e 100644
--- a/sw/source/core/docnode/ndindex.cxx
+++ b/sw/source/core/docnode/ndindex.cxx
@@ -44,7 +44,7 @@ SwNodeRange::SwNodeRange( const SwNode& rS, long nSttDiff,
 SwNodeIndex::SwNodeIndex( SwNodes& rNds, sal_uLong nIdx )
     : pNd( rNds[ nIdx ] )
 {
-    rNds.RegisterIndex( *this );
+    RegisterIndex( rNds );
 }
 
 SwNodeIndex::SwNodeIndex( const SwNodeIndex& rIdx, long nDiff )
@@ -55,7 +55,7 @@ SwNodeIndex::SwNodeIndex( const SwNodeIndex& rIdx, long nDiff )
     else
         pNd = rIdx.pNd;
 
-    pNd->GetNodes().RegisterIndex( *this );
+    RegisterIndex( pNd->GetNodes() );
 }
 
 SwNodeIndex::SwNodeIndex( const SwNode& rNd, long nDiff )
@@ -65,21 +65,21 @@ SwNodeIndex::SwNodeIndex( const SwNode& rNd, long nDiff )
     else
         pNd = (SwNode*)&rNd;
 
-    pNd->GetNodes().RegisterIndex( *this );
+    RegisterIndex( pNd->GetNodes() );
 }
 
 void SwNodeIndex::Remove()
 {
-    pNd->GetNodes().DeRegisterIndex( *this );
+    DeRegisterIndex( pNd->GetNodes() );
 }
 
 SwNodeIndex& SwNodeIndex::operator=( const SwNodeIndex& rIdx )
 {
     if( &pNd->GetNodes() != &rIdx.pNd->GetNodes() )
     {
-        pNd->GetNodes().DeRegisterIndex( *this );
+        DeRegisterIndex( pNd->GetNodes() );
         pNd = rIdx.pNd;
-        pNd->GetNodes().RegisterIndex( *this );
+        RegisterIndex( pNd->GetNodes() );
     }
     else
         pNd = rIdx.pNd;
@@ -90,9 +90,9 @@ SwNodeIndex& SwNodeIndex::operator=( const SwNode& rNd )
 {
     if( &pNd->GetNodes() != &rNd.GetNodes() )
     {
-        pNd->GetNodes().DeRegisterIndex( *this );
+        DeRegisterIndex( pNd->GetNodes() );
         pNd = (SwNode*)&rNd;
-        pNd->GetNodes().RegisterIndex( *this );
+        RegisterIndex( pNd->GetNodes() );
     }
     else
         pNd = (SwNode*)&rNd;
@@ -103,9 +103,9 @@ SwNodeIndex& SwNodeIndex::Assign( SwNodes& rNds, sal_uLong nIdx )
 {
     if( &pNd->GetNodes() != &rNds )
     {
-        pNd->GetNodes().DeRegisterIndex( *this );
+        DeRegisterIndex( pNd->GetNodes() );
         pNd = rNds[ nIdx ];
-        pNd->GetNodes().RegisterIndex( *this );
+        RegisterIndex( pNd->GetNodes() );
     }
     else
         pNd = rNds[ nIdx ];
@@ -116,9 +116,9 @@ SwNodeIndex& SwNodeIndex::Assign( const SwNode& rNd, long nOffset )
 {
     if( &pNd->GetNodes() != &rNd.GetNodes() )
     {
-        pNd->GetNodes().DeRegisterIndex( *this );
+        DeRegisterIndex( pNd->GetNodes() );
         pNd = (SwNode*)&rNd;
-        pNd->GetNodes().RegisterIndex( *this );
+        RegisterIndex( pNd->GetNodes() );
     }
     else
         pNd = (SwNode*)&rNd;
diff --git a/sw/source/core/docnode/nodes.cxx b/sw/source/core/docnode/nodes.cxx
index 3167f8a..b9c91ad 100644
--- a/sw/source/core/docnode/nodes.cxx
+++ b/sw/source/core/docnode/nodes.cxx
@@ -2313,18 +2313,4 @@ bool SwNodes::IsDocNodes() const
     return this == &pMyDoc->GetNodes();
 }
 
-void SwNodes::RegisterIndex( SwNodeIndex& rIdx )
-{
-    if(!vIndices)
-        vIndices = &rIdx;
-    rIdx.MoveTo(vIndices);
-}
-void SwNodes::DeRegisterIndex( SwNodeIndex& rIdx )
-{
-    if(vIndices == &rIdx)
-        vIndices = vIndices->GetNextInRing();
-    rIdx.MoveTo(nullptr);
-    if(vIndices == &rIdx)
-        vIndices = nullptr;
-}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 82ef5f9eab317171d4b08f5471222cce8f1fcdbf
Author: Bjoern Michaelsen <bjoern.michaelsen at canonical.com>
Date:   Fri Dec 19 02:05:44 2014 +0100

    use sw::Ring instead

diff --git a/sw/inc/ndarr.hxx b/sw/inc/ndarr.hxx
index e60b9ee..c7979da 100644
--- a/sw/inc/ndarr.hxx
+++ b/sw/inc/ndarr.hxx
@@ -21,6 +21,7 @@
 #define INCLUDED_SW_INC_NDARR_HXX
 
 #include <vector>
+#include <memory>
 
 #include <boost/utility.hpp>
 
@@ -31,6 +32,7 @@
 #include <bparr.hxx>
 #include <ndtyp.hxx>
 #include <o3tl/sorted_vector.hxx>
+#include <ring.hxx>
 
 class Graphic;
 class GraphicObject;
@@ -93,7 +95,7 @@ class SW_DLLPUBLIC SwNodes
     friend class SwStartNode;
     friend class ::sw::DocumentContentOperationsManager;
 
-    SwNodeIndex* pRoot;                 ///< List of all indices on nodes.
+    SwNodeIndex* vIndices; ///< ring of all indices on nodes.
 
     void InsertNode( const SwNodePtr pNode,
                      const SwNodeIndex& rPos );
diff --git a/sw/inc/ndindex.hxx b/sw/inc/ndindex.hxx
index 836e4b8..e0439cc 100644
--- a/sw/inc/ndindex.hxx
+++ b/sw/inc/ndindex.hxx
@@ -25,19 +25,16 @@
 #include <tools/solar.h>
 
 #include <node.hxx>
+#include <ring.hxx>
 
 class SwNode;
 class SwNodes;
 
 /// Marks a node in the document model.
-class SW_DLLPUBLIC SwNodeIndex SAL_FINAL
+class SW_DLLPUBLIC SwNodeIndex SAL_FINAL : public sw::Ring<SwNodeIndex>
 {
-    friend void SwNodes::RegisterIndex( SwNodeIndex& );
     friend void SwNodes::DeRegisterIndex( SwNodeIndex& );
-    friend void SwNodes::RemoveNode( sal_uLong, sal_uLong, bool );
-
     SwNode* pNd;
-    SwNodeIndex *pNext, *pPrev;
 
     void Remove();
 
diff --git a/sw/inc/ring.hxx b/sw/inc/ring.hxx
index e4c62f5..85f62bd 100644
--- a/sw/inc/ring.hxx
+++ b/sw/inc/ring.hxx
@@ -216,7 +216,7 @@ namespace sw
         private:
             friend class boost::iterator_core_access;
             void increment()
-                { m_pCurrent = m_pCurrent ? m_pCurrent->GetNextInRing() : m_pStart->GetNext(); }
+                { m_pCurrent = m_pCurrent ? m_pCurrent->GetNextInRing() : m_pStart->GetNextInRing(); }
             bool equal(RingIterator const& other) const
             {
                 // we never want to compare iterators from
diff --git a/sw/source/core/docnode/ndindex.cxx b/sw/source/core/docnode/ndindex.cxx
index 03e98be..3656000 100644
--- a/sw/source/core/docnode/ndindex.cxx
+++ b/sw/source/core/docnode/ndindex.cxx
@@ -42,13 +42,13 @@ SwNodeRange::SwNodeRange( const SwNode& rS, long nSttDiff,
 {}
 
 SwNodeIndex::SwNodeIndex( SwNodes& rNds, sal_uLong nIdx )
-    : pNd( rNds[ nIdx ] ), pNext( 0 ), pPrev( 0 )
+    : pNd( rNds[ nIdx ] )
 {
     rNds.RegisterIndex( *this );
 }
 
 SwNodeIndex::SwNodeIndex( const SwNodeIndex& rIdx, long nDiff )
-    : pNext( 0 ), pPrev( 0 )
+    : sw::Ring<SwNodeIndex>()
 {
     if( nDiff )
         pNd = rIdx.GetNodes()[ rIdx.GetIndex() + nDiff ];
@@ -59,7 +59,6 @@ SwNodeIndex::SwNodeIndex( const SwNodeIndex& rIdx, long nDiff )
 }
 
 SwNodeIndex::SwNodeIndex( const SwNode& rNd, long nDiff )
-    : pNext( 0 ), pPrev( 0 )
 {
     if( nDiff )
         pNd = rNd.GetNodes()[ rNd.GetIndex() + nDiff ];
diff --git a/sw/source/core/docnode/nodes.cxx b/sw/source/core/docnode/nodes.cxx
index 00b9a87..3167f8a 100644
--- a/sw/source/core/docnode/nodes.cxx
+++ b/sw/source/core/docnode/nodes.cxx
@@ -57,7 +57,7 @@ sal_uInt16 HighestLevel( SwNodes & rNodes, const SwNodeRange & rRange );
  * @param pDocument TODO: provide documentation
  */
 SwNodes::SwNodes( SwDoc* pDocument )
-    : pRoot( 0 ), pMyDoc( pDocument )
+    : vIndices(nullptr), pMyDoc( pDocument )
 {
     bInNodesDel = bInDelUpdOutl = bInDelUpdNum = false;
 
@@ -2212,29 +2212,11 @@ void SwNodes::RemoveNode( sal_uLong nDelPos, sal_uLong nSz, bool bDel )
     sal_uLong nEnd = nDelPos + nSz;
     SwNode* pNew = (*this)[ nEnd ];
 
-    if( pRoot )
+    for(SwNodeIndex& rIndex : vIndices->GetRingContainer())
     {
-        SwNodeIndex *p = pRoot;
-        while( p )
-        {
-            sal_uLong nIdx = p->GetIndex();
-            SwNodeIndex* pNext = p->pNext;
-            if( nDelPos <= nIdx && nIdx < nEnd )
-                (*p) = *pNew;
-
-            p = pNext;
-        }
-
-        p = pRoot->pPrev;
-        while( p )
-        {
-            sal_uLong nIdx = p->GetIndex();
-            SwNodeIndex* pPrev = p->pPrev;
-            if( nDelPos <= nIdx && nIdx < nEnd )
-                (*p) = *pNew;
-
-            p = pPrev;
-        }
+        sal_uLong nIdx = rIndex.GetIndex();
+        if( nDelPos <= nIdx && nIdx < nEnd )
+            rIndex = *pNew;
     }
 
     {
@@ -2288,42 +2270,6 @@ void SwNodes::RemoveNode( sal_uLong nDelPos, sal_uLong nSz, bool bDel )
     BigPtrArray::Remove( nDelPos, nSz );
 }
 
-void SwNodes::RegisterIndex( SwNodeIndex& rIdx )
-{
-    if( !pRoot ) // no root set, yet?
-    {
-        pRoot = &rIdx;
-        pRoot->pPrev = 0;
-        pRoot->pNext = 0;
-    }
-    else
-    {
-        // add always after root
-        rIdx.pNext = pRoot->pNext;
-        pRoot->pNext = &rIdx;
-        rIdx.pPrev = pRoot;
-        if( rIdx.pNext )
-            rIdx.pNext->pPrev = &rIdx;
-    }
-}
-
-void SwNodes::DeRegisterIndex( SwNodeIndex& rIdx )
-{
-    SwNodeIndex* pN = rIdx.pNext;
-    SwNodeIndex* pP = rIdx.pPrev;
-
-    if( pRoot == &rIdx )
-        pRoot = pP ? pP : pN;
-
-    if( pP )
-        pP->pNext = pN;
-    if( pN )
-        pN->pPrev = pP;
-
-    rIdx.pNext = 0;
-    rIdx.pPrev = 0;
-}
-
 void SwNodes::InsertNode( const SwNodePtr pNode,
                           const SwNodeIndex& rPos )
 {
@@ -2367,4 +2313,18 @@ bool SwNodes::IsDocNodes() const
     return this == &pMyDoc->GetNodes();
 }
 
+void SwNodes::RegisterIndex( SwNodeIndex& rIdx )
+{
+    if(!vIndices)
+        vIndices = &rIdx;
+    rIdx.MoveTo(vIndices);
+}
+void SwNodes::DeRegisterIndex( SwNodeIndex& rIdx )
+{
+    if(vIndices == &rIdx)
+        vIndices = vIndices->GetNextInRing();
+    rIdx.MoveTo(nullptr);
+    if(vIndices == &rIdx)
+        vIndices = nullptr;
+}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list