1
0
mirror of https://github.com/OlafvdSpek/ctemplate.git synced 2025-09-28 19:05:49 +08:00

Use find_ptr

This commit is contained in:
olafvdspek 2015-02-15 00:28:41 +00:00
parent 3f45c961e9
commit 4e26363259

View File

@ -419,18 +419,17 @@ bool TemplateCache::ExpandNoLoad(
ExpandEmitter *expand_emitter) const { ExpandEmitter *expand_emitter) const {
TemplateCacheKey template_cache_key(filename.GetGlobalId(), strip); TemplateCacheKey template_cache_key(filename.GetGlobalId(), strip);
CachedTemplate cached_tpl; CachedTemplate cached_tpl;
TemplateMap::iterator it;
{ {
ReaderMutexLock ml(mutex_); ReaderMutexLock ml(mutex_);
if (!is_frozen_) { if (!is_frozen_) {
LOG(DFATAL) << ": ExpandNoLoad() only works on frozen caches."; LOG(DFATAL) << ": ExpandNoLoad() only works on frozen caches.";
return false; return false;
} }
it = parsed_template_cache_->find(template_cache_key); CachedTemplate* it = find_ptr(*parsed_template_cache_, template_cache_key);
if (it == parsed_template_cache_->end()) { if (!it) {
return false; return false;
} }
cached_tpl = it->second; cached_tpl = *it;
cached_tpl.refcounted_tpl->IncRef(); cached_tpl.refcounted_tpl->IncRef();
} }
const bool result = cached_tpl.refcounted_tpl->tpl()->ExpandWithDataAndCache( 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 { int TemplateCache::Refcount(const TemplateCacheKey template_cache_key) const {
ReaderMutexLock ml(mutex_); ReaderMutexLock ml(mutex_);
TemplateMap::const_iterator it = CachedTemplate* it = find_ptr(*parsed_template_cache_, template_cache_key);
parsed_template_cache_->find(template_cache_key); return it ? it->refcounted_tpl->refcount() : 0;
if (it != parsed_template_cache_->end()) {
return it->second.refcounted_tpl->refcount();
} else {
return 0;
}
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -750,8 +744,7 @@ int TemplateCache::Refcount(const TemplateCacheKey template_cache_key) const {
bool TemplateCache::TemplateIsCached(const TemplateCacheKey template_cache_key) bool TemplateCache::TemplateIsCached(const TemplateCacheKey template_cache_key)
const { const {
ReaderMutexLock ml(mutex_); ReaderMutexLock ml(mutex_);
return (parsed_template_cache_->find(template_cache_key) != return parsed_template_cache_->count(template_cache_key);
parsed_template_cache_->end());
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------