From bc5d61ae355112e57b9a1c372bfb550f1c8bd6d4 Mon Sep 17 00:00:00 2001 From: xy Date: Sun, 13 Nov 2011 10:05:13 +0800 Subject: [PATCH] Changing from boost multi_index MRU to ATL style MRU. --- .../transform/vsfilter/DirectVobSubFilter.cpp | 16 ++++++------- src/subtitles/RTS.cpp | 26 ++++++++++------------ src/subtitles/cache_manager.cpp | 4 ++-- src/subtitles/cache_manager.h | 24 +++++--------------- src/subtitles/subpixel_position_controler.cpp | 1 - 5 files changed, 28 insertions(+), 43 deletions(-) diff --git a/src/filters/transform/vsfilter/DirectVobSubFilter.cpp b/src/filters/transform/vsfilter/DirectVobSubFilter.cpp index 1cb71aa..810ba30 100644 --- a/src/filters/transform/vsfilter/DirectVobSubFilter.cpp +++ b/src/filters/transform/vsfilter/DirectVobSubFilter.cpp @@ -575,7 +575,7 @@ void CDirectVobSubFilter::InitSubPicQueue() CacheManager::GetPathDataMruCache()->SetMaxItemNum(m_path_data_cache_max_item_num); CacheManager::GetScanLineDataMruCache()->SetMaxItemNum(m_scan_line_data_cache_max_item_num); CacheManager::GetOverlayNoBlurMruCache()->SetMaxItemNum(m_overlay_no_blur_cache_max_item_num); - CacheManager::GetOverlayMruCache()->set_max_num_items(m_overlay_cache_max_item_num); + CacheManager::GetOverlayMruCache()->SetMaxItemNum(m_overlay_cache_max_item_num); SubpixelPositionControler::GetGlobalControler().SetSubpixelLevel( static_cast(m_subpixel_pos_level) ); m_pSubPicQueue = NULL; @@ -1106,7 +1106,7 @@ STDMETHODIMP CDirectVobSubFilter::put_OverlayCacheMaxItemNum( int overlay_cache_ if(hr == NOERROR) { - CacheManager::GetOverlayMruCache()->set_max_num_items(m_overlay_cache_max_item_num); + CacheManager::GetOverlayMruCache()->SetMaxItemNum(m_overlay_cache_max_item_num); } return hr; @@ -1165,13 +1165,13 @@ STDMETHODIMP CDirectVobSubFilter::get_CachesInfo(CachesInfo* caches_info) caches_info->non_blur_cache_cur_item_num= CacheManager::GetOverlayNoBlurMruCache()->GetCurItemNum(); caches_info->non_blur_cache_hit_count = CacheManager::GetOverlayNoBlurMruCache()->GetCacheHitCount(); caches_info->non_blur_cache_query_count = CacheManager::GetOverlayNoBlurMruCache()->GetQueryCount(); - caches_info->overlay_cache_cur_item_num = CacheManager::GetOverlayMruCache()->get_cur_items_num(); - caches_info->overlay_cache_hit_count = CacheManager::GetOverlayMruCache()->get_cache_hit(); - caches_info->overlay_cache_query_count = CacheManager::GetOverlayMruCache()->get_query_count(); + caches_info->overlay_cache_cur_item_num = CacheManager::GetOverlayMruCache()->GetCurItemNum(); + caches_info->overlay_cache_hit_count = CacheManager::GetOverlayMruCache()->GetCacheHitCount(); + caches_info->overlay_cache_query_count = CacheManager::GetOverlayMruCache()->GetQueryCount(); - caches_info->interpolate_cache_cur_item_num = CacheManager::GetSubpixelVarianceCache()->get_cur_items_num(); - caches_info->interpolate_cache_hit_count = CacheManager::GetSubpixelVarianceCache()->get_cache_hit(); - caches_info->interpolate_cache_query_count = CacheManager::GetSubpixelVarianceCache()->get_query_count(); + caches_info->interpolate_cache_cur_item_num = CacheManager::GetSubpixelVarianceCache()->GetCurItemNum(); + caches_info->interpolate_cache_hit_count = CacheManager::GetSubpixelVarianceCache()->GetCacheHitCount(); + caches_info->interpolate_cache_query_count = CacheManager::GetSubpixelVarianceCache()->GetQueryCount(); caches_info->text_info_cache_cur_item_num = CacheManager::GetAssTagListMruCache()->GetCurItemNum(); caches_info->text_info_cache_hit_count = CacheManager::GetAssTagListMruCache()->GetCacheHitCount(); caches_info->text_info_cache_query_count = CacheManager::GetAssTagListMruCache()->GetQueryCount(); diff --git a/src/subtitles/RTS.cpp b/src/subtitles/RTS.cpp index a4e5199..c991e42 100644 --- a/src/subtitles/RTS.cpp +++ b/src/subtitles/RTS.cpp @@ -210,11 +210,11 @@ void CWord::Paint( SharedPtrCWord word, const CPoint& p, const CPoint& org, Over OverlayMruCache* overlay_cache = CacheManager::GetSubpixelVarianceCache(); - OverlayMruCache::hashed_cache_const_iterator iter = overlay_cache->hash_find(sub_key); - if(iter!=overlay_cache->hash_end()) + POSITION pos = overlay_cache->Lookup(sub_key); + if(pos!=NULL) { - overlay_list->overlay = iter->overlay; - overlay_cache->update_cache( *iter ); + overlay_list->overlay = overlay_cache->GetAt(pos); + overlay_cache->UpdateCache( pos ); } } if( !overlay_list->overlay ) @@ -222,21 +222,20 @@ void CWord::Paint( SharedPtrCWord word, const CPoint& p, const CPoint& org, Over CPoint psub = SubpixelPositionControler::GetGlobalControler().GetSubpixel(p); OverlayKey overlay_key(*word, psub, trans_org); OverlayMruCache* overlay_cache = CacheManager::GetOverlayMruCache(); - OverlayMruCache::hashed_cache_const_iterator iter = overlay_cache->hash_find(overlay_key); - if(iter==overlay_cache->hash_end()) + POSITION pos = overlay_cache->Lookup(overlay_key); + if(pos==NULL) { if( !word->DoPaint(psub, trans_org, &(overlay_list->overlay), overlay_key) ) { error = true; break; } - OverlayMruItem item(overlay_key, overlay_list->overlay); - overlay_cache->update_cache(item); + overlay_cache->UpdateCache(overlay_key, overlay_list->overlay); } else { - overlay_list->overlay = iter->overlay; - overlay_cache->update_cache( *iter ); + overlay_list->overlay = overlay_cache->GetAt(pos); + overlay_cache->UpdateCache( pos ); } if( SubpixelPositionControler::GetGlobalControler().UseBilinearShift() && (psub.x!=(p.x&SubpixelPositionControler::EIGHT_X_EIGHT_MASK) @@ -246,9 +245,8 @@ void CWord::Paint( SharedPtrCWord word, const CPoint& p, const CPoint& org, Over (p.y&SubpixelPositionControler::EIGHT_X_EIGHT_MASK) - psub.y)); CPoint psub_true( (p.x&SubpixelPositionControler::EIGHT_X_EIGHT_MASK), (p.y&SubpixelPositionControler::EIGHT_X_EIGHT_MASK) ); OverlayKey sub_key(*word, psub_true, trans_org); - OverlayMruCache* overlay_cache = CacheManager::GetSubpixelVarianceCache(); - OverlayMruItem item(sub_key, overlay_list->overlay); - overlay_cache->update_cache(item); + OverlayMruCache* overlay_cache = CacheManager::GetSubpixelVarianceCache(); + overlay_cache->UpdateCache(sub_key, overlay_list->overlay); } } @@ -1869,7 +1867,7 @@ void CRenderedTextSubtitle::Deinit() CacheManager::GetPathDataMruCache()->RemoveAll(); CacheManager::GetScanLineDataMruCache()->RemoveAll(); CacheManager::GetOverlayNoBlurMruCache()->RemoveAll(); - CacheManager::GetOverlayMruCache()->clear(); + CacheManager::GetOverlayMruCache()->RemoveAll(); } void CRenderedTextSubtitle::ParseEffect(CSubtitle* sub, const CStringW& str) diff --git a/src/subtitles/cache_manager.cpp b/src/subtitles/cache_manager.cpp index f342b46..deb24db 100644 --- a/src/subtitles/cache_manager.cpp +++ b/src/subtitles/cache_manager.cpp @@ -55,9 +55,9 @@ ULONG OverlayNoBlurKeyTraits::Hash( const OverlayNoBlurKey& key ) return hash; } -std::size_t hash_value(const OverlayKey& key) +ULONG OverlayKeyTraits::Hash( const OverlayKey& key ) { - size_t hash = OverlayNoBlurKeyTraits::Hash(static_cast(key)); + ULONG hash = OverlayNoBlurKeyTraits::Hash(static_cast(key)); hash += (hash<<5); hash += key.m_style.get().fBlur; hash += (hash<<5); diff --git a/src/subtitles/cache_manager.h b/src/subtitles/cache_manager.h index 0bd2228..d215626 100644 --- a/src/subtitles/cache_manager.h +++ b/src/subtitles/cache_manager.h @@ -91,7 +91,7 @@ public: bool operator==(const OverlayKey& key)const; - friend std::size_t hash_value(const OverlayKey& key); + friend class OverlayKeyTraits; }; std::size_t hash_value(const CWord& key); @@ -126,26 +126,12 @@ public: static ULONG Hash(const OverlayNoBlurKey& key); }; -std::size_t hash_value(const OverlayKey& key); - -//shouldn't use std::pair, or else VC complaining error C2440 -//typedef std::pair OverlayMruItem; -struct OverlayMruItem +class OverlayKeyTraits:public CElementTraits { - OverlayMruItem(const OverlayKey& overlay_key_, const SharedPtrOverlay& overlay_):overlay_key(overlay_key_),overlay(overlay_){} - - OverlayKey overlay_key; - SharedPtrOverlay overlay; +public: + static ULONG Hash(const OverlayKey& key); }; -typedef enhanced_mru_list< - OverlayMruItem, - boost::multi_index::member -> OverlayMruCache; - typedef EnhancedXyMru< TextInfoCacheKey, CText::SharedPtrTextInfo, @@ -166,6 +152,8 @@ typedef EnhancedXyMru OverlayNoBlurMruCache; +typedef EnhancedXyMru OverlayMruCache; + class CacheManager { public: diff --git a/src/subtitles/subpixel_position_controler.cpp b/src/subtitles/subpixel_position_controler.cpp index 4a839d7..94f071e 100644 --- a/src/subtitles/subpixel_position_controler.cpp +++ b/src/subtitles/subpixel_position_controler.cpp @@ -30,7 +30,6 @@ SubpixelPositionControler::SUBPIXEL_LEVEL SubpixelPositionControler::SetSubpixel break; } _subpixel_level = subpixel_level; - CacheManager::GetOverlayMruCache()->clear(); } return subpixel_level; } -- 2.11.4.GIT