]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/blockallocator.cpp
Fix BlockAllocator so that it actually compiles
[r2c2.git] / source / libr2c2 / blockallocator.cpp
index 7dcc15b57acdf268ab6dc92ecf5bad2f91570158..39550394b2ac5c0cc0fa6aada82170a49590025d 100644 (file)
@@ -92,7 +92,7 @@ const BlockIter &BlockAllocator::last_current() const
 
 const BlockIter &BlockAllocator::iter_for(const Block &block) const
 {
-       BlockList::const_iterator i = find_if(blocks.begin(), blocks.end(), IterBlockMatch(block));
+       BlockList::const_iterator i = find_if(blocks.begin(), blocks.end(), BlockMatch(block));
        if(i==blocks.end())
                throw key_error(&block);
        return *i;
@@ -100,12 +100,13 @@ const BlockIter &BlockAllocator::iter_for(const Block &block) const
 
 bool BlockAllocator::has_block(const Block &block) const
 {
-       return find_if(blocks.begin(), blocks.end(), IterBlockMatch(block))!=blocks.end();
+       return find_if(blocks.begin(), blocks.end(), BlockMatch(block))!=blocks.end();
 }
 
 bool BlockAllocator::is_block_current(const Block &block) const
 {
-       return find_if(blocks.begin(), cur_blocks_end, IterBlockMatch(block))!=cur_blocks_end;
+       BlockList::const_iterator end = cur_blocks_end;
+       return find_if(blocks.begin(), end, BlockMatch(block))!=cur_blocks_end;
 }
 
 void BlockAllocator::reserve_more()
@@ -267,10 +268,13 @@ void BlockAllocator::release_blocks_end(const BlockList::iterator &begin)
        if(begin==blocks.begin())
                return release_blocks_begin(blocks.end());
 
+       if(begin==blocks.end())
+               return;
+
        /* Release the blocks in reverse order so that a consistent state is
        presented in block_reserved signal. */
        bool done = false;
-       for(BlockList::iterator i=blocks.end(); !done; )
+       for(BlockList::iterator i=--blocks.end(); !done; )
        {
                done = (i==begin);
                release_block(i--);