From 9ba9a7bd0d4e58189352ca58f24d7f37b0ae9f20 Mon Sep 17 00:00:00 2001 From: Sascha Volkenandt Date: Thu, 31 May 2007 16:49:05 +0000 Subject: - slight optimisation --- cache.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cache.h b/cache.h index 0b81cf5..4b78ee5 100755 --- a/cache.h +++ b/cache.h @@ -68,16 +68,25 @@ public: m_currentWeight -= result->weight(); m_values.erase( it->second ); - m_lookup.erase( it ); + //m_lookup.erase( it ); } - if ( !result->load() ) + if ( !result->load() ) { + if ( it != m_lookup.end() ) + m_lookup.erase( it ); return ptr_type(); + } // put new object into cache if ( result->weight() < m_maxWeight ) { m_currentWeight += result->weight(); - m_lookup.insert( std::make_pair( key, m_values.insert( m_values.begin(), std::make_pair( key, result ) ) ) ); + + typename ValueList::iterator element = m_values.insert( m_values.begin(), std::make_pair( key, result ) ); + if ( it != m_lookup.end() ) + it->second = element; + else + m_lookup.insert( std::make_pair( key, element ) ); + while ( m_currentWeight > m_maxWeight ) { value_type& value = m_values.back(); m_currentWeight -= value.second->weight(); -- cgit v1.2.3