From 4e26363259227ee6e4d3e947866ca9f4ca7fbc4c Mon Sep 17 00:00:00 2001 From: olafvdspek Date: Sun, 15 Feb 2015 00:28:41 +0000 Subject: [PATCH] Use find_ptr --- trunk/src/template_cache.cc | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/trunk/src/template_cache.cc b/trunk/src/template_cache.cc index f61f637..1067b01 100644 --- a/trunk/src/template_cache.cc +++ b/trunk/src/template_cache.cc @@ -419,18 +419,17 @@ bool TemplateCache::ExpandNoLoad( ExpandEmitter *expand_emitter) const { TemplateCacheKey template_cache_key(filename.GetGlobalId(), strip); CachedTemplate cached_tpl; - TemplateMap::iterator it; { ReaderMutexLock ml(mutex_); if (!is_frozen_) { LOG(DFATAL) << ": ExpandNoLoad() only works on frozen caches."; return false; } - it = parsed_template_cache_->find(template_cache_key); - if (it == parsed_template_cache_->end()) { + CachedTemplate* it = find_ptr(*parsed_template_cache_, template_cache_key); + if (!it) { return false; } - cached_tpl = it->second; + cached_tpl = *it; cached_tpl.refcounted_tpl->IncRef(); } const bool result = cached_tpl.refcounted_tpl->tpl()->ExpandWithDataAndCache( @@ -732,13 +731,8 @@ TemplateCache* TemplateCache::Clone() const { int TemplateCache::Refcount(const TemplateCacheKey template_cache_key) const { ReaderMutexLock ml(mutex_); - TemplateMap::const_iterator it = - parsed_template_cache_->find(template_cache_key); - if (it != parsed_template_cache_->end()) { - return it->second.refcounted_tpl->refcount(); - } else { - return 0; - } + CachedTemplate* it = find_ptr(*parsed_template_cache_, template_cache_key); + return it ? it->refcounted_tpl->refcount() : 0; } // ---------------------------------------------------------------------- @@ -750,8 +744,7 @@ int TemplateCache::Refcount(const TemplateCacheKey template_cache_key) const { bool TemplateCache::TemplateIsCached(const TemplateCacheKey template_cache_key) const { ReaderMutexLock ml(mutex_); - return (parsed_template_cache_->find(template_cache_key) != - parsed_template_cache_->end()); + return parsed_template_cache_->count(template_cache_key); } // ----------------------------------------------------------------------