tools/source/memtools/unqidx.cxx |   17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

New commits:
commit bc2e74f3c3093819c499921cf62615e9a8d7301c
Author: Matteo Casalin <matteo.casa...@yahoo.com>
Date:   Sat Mar 5 14:35:25 2016 +0100

    Simplify recycling/search of freed UniqueIndex-es
    
    Change-Id: Icb8b375a95718a72abdd6650dda49fb9f43026a4
    Reviewed-on: https://gerrit.libreoffice.org/22934
    Reviewed-by: Noel Grandin <noelgran...@gmail.com>
    Tested-by: Noel Grandin <noelgran...@gmail.com>

diff --git a/tools/source/memtools/unqidx.cxx b/tools/source/memtools/unqidx.cxx
index ecc6232..56a9f0a 100644
--- a/tools/source/memtools/unqidx.cxx
+++ b/tools/source/memtools/unqidx.cxx
@@ -25,14 +25,10 @@ UniqueIndexImpl::Index UniqueIndexImpl::Insert( void* p )
     if ( !p )
         return IndexNotFound;
 
-    const Index nTmp = static_cast<Index>(maMap.size()) + 1;
-
-    // Avoid overflow of UniqIndex upon deletion
-    nUniqIndex = nUniqIndex % nTmp;
-
-    // Search next empty index
+    // Search next unused index, may be needed after
+    // a removal followed by multiple insertions
     while ( maMap.find( nUniqIndex ) != maMap.end() )
-        nUniqIndex = (nUniqIndex+1) % nTmp;
+        ++nUniqIndex;
 
     maMap[ nUniqIndex ] = p;
 
@@ -48,6 +44,13 @@ void* UniqueIndexImpl::Remove( Index nIndex )
         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;
+
             void* p = it->second;
             maMap.erase( it );
             return p;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to