include/tools/unqidx.hxx         |    6 ++----
 tools/source/memtools/unqidx.cxx |   39 +++++++++++++++------------------------
 2 files changed, 17 insertions(+), 28 deletions(-)

New commits:
commit 078188793b2753bf607bb629464935ccefd28136
Author: Matteo Casalin <matteo.casa...@yahoo.com>
Date:   Sat Mar 5 14:59:11 2016 +0100

    Remove unuseful nStartIndex data member (and fix indexing)
    
    The methods that modify nUinqIndex already maintain class invariants:
    * Insert() never decrease its value
    * Remove() can replace its value with that of the removed item,
      which was no lower than the one specified in constructor call.
    Besides, boundary checks against nStartIndex are not really needed
    since the various methods rely on map::find.
    
    Finally, FirstIndex/NextIndex/LastIndex/GetIndexOf did not adjust with
    nStartIndex the index value retrieved from tha map, thus provifing wrong
    values. Since the map now stores the real indexes, consistency is granted.
    
    Change-Id: I5e47cd2672677805304d4c4860826fe272812abf
    Reviewed-on: https://gerrit.libreoffice.org/22935
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Noel Grandin <noelgran...@gmail.com>

diff --git a/include/tools/unqidx.hxx b/include/tools/unqidx.hxx
index b6d65b4..99c5655 100644
--- a/include/tools/unqidx.hxx
+++ b/include/tools/unqidx.hxx
@@ -31,13 +31,11 @@ public:
 
 private:
     std::map<Index, void*> maMap;
-    const Index nStartIndex;
     Index nUniqIndex;
 
 public:
-    UniqueIndexImpl( Index _nStartIndex = 0 )
-        : maMap(),
-          nStartIndex(_nStartIndex), nUniqIndex(_nStartIndex) {}
+    UniqueIndexImpl( Index nStartIndex = 0 )
+        : maMap(), nUniqIndex(nStartIndex) {}
 
     Index Insert( void* p );
     // insert value with key, replacing existing entry if necessary
diff --git a/tools/source/memtools/unqidx.cxx b/tools/source/memtools/unqidx.cxx
index 56a9f0a..b53895f 100644
--- a/tools/source/memtools/unqidx.cxx
+++ b/tools/source/memtools/unqidx.cxx
@@ -32,42 +32,33 @@ UniqueIndexImpl::Index UniqueIndexImpl::Insert( void* p )
 
     maMap[ nUniqIndex ] = p;
 
-    nUniqIndex++;
-    return ( nUniqIndex + nStartIndex - 1 );
+    return nUniqIndex++;
 }
 
 void* UniqueIndexImpl::Remove( Index nIndex )
 {
-    // Check for valid index
-    if ( nIndex >= nStartIndex )
+    std::map<Index, void*>::iterator it = maMap.find( nIndex );
+    if ( it != maMap.end() )
     {
-        std::map<Index, void*>::iterator it = maMap.find( nIndex - nStartIndex 
);
-        if( it != maMap.end() )
-        {
-            // Allow to recycle freed indexes, as was done by
-            // original implementation based on a vector
-            // This is not really needed when using a map, and
-            // really unique indexes might be better/safer?
-            if ( nIndex < nUniqIndex )
-                nUniqIndex = nIndex;
+        // Allow to recycle freed indexes, as was done by
+        // original implementation based on a vector
+        // This is not really needed when using a map, and
+        // really unique indexes might be better/safer?
+        if ( nIndex < nUniqIndex )
+            nUniqIndex = nIndex;
 
-            void* p = it->second;
-            maMap.erase( it );
-            return p;
-        }
+        void* p = it->second;
+        maMap.erase( it );
+        return p;
     }
     return nullptr;
 }
 
 void* UniqueIndexImpl::Get( Index nIndex ) const
 {
-    // check for valid index
-    if ( nIndex >= nStartIndex )
-    {
-        std::map<Index, void*>::const_iterator it = maMap.find( nIndex - 
nStartIndex );
-        if( it != maMap.end() )
-            return it->second;
-    }
+    std::map<Index, void*>::const_iterator it = maMap.find( nIndex );
+    if ( it != maMap.end() )
+        return it->second;
     return nullptr;
 }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to