summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMatteo Casalin <matteo.casalin@yahoo.com>2016-03-05 14:35:25 +0100
committerNoel Grandin <noelgrandin@gmail.com>2016-03-06 06:37:05 +0000
commitbc2e74f3c3093819c499921cf62615e9a8d7301c (patch)
treec907502f065d96aa9eecc6fefa981846354bb73e /tools
parentcd0c89f768870f0a9540bb9cffc9a7ea953bb297 (diff)
Simplify recycling/search of freed UniqueIndex-es
Change-Id: Icb8b375a95718a72abdd6650dda49fb9f43026a4 Reviewed-on: https://gerrit.libreoffice.org/22934 Reviewed-by: Noel Grandin <noelgrandin@gmail.com> Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/source/memtools/unqidx.cxx17
1 files changed, 10 insertions, 7 deletions
diff --git a/tools/source/memtools/unqidx.cxx b/tools/source/memtools/unqidx.cxx
index ecc6232f882b..56a9f0aaa143 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;