diff options
Diffstat (limited to 'tools/source/memtools/unqidx.cxx')
-rw-r--r-- | tools/source/memtools/unqidx.cxx | 17 |
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; |