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:
parent
fdf31135e3
commit
3f45c961e9
|
@ -33,10 +33,19 @@
|
|||
#ifndef TEMPLATE_FIND_PTR_H_
|
||||
#define TEMPLATE_FIND_PTR_H_
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
@ac_windows_dllexport_defines@
|
||||
|
||||
namespace ctemplate {
|
||||
|
||||
template <class T, class U>
|
||||
const typename T::value_type* find_ptr0(const T& c, U v)
|
||||
{
|
||||
typename T::const_iterator i = c.find(v);
|
||||
return i == c.end() ? NULL : &*i;
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
typename T::value_type::second_type* find_ptr(T& c, U v)
|
||||
{
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
// introduce new include dependencies.
|
||||
|
||||
#include <config.h>
|
||||
#include <ctemplate/find_ptr.h>
|
||||
#include <ctemplate/per_expand_data.h>
|
||||
#include <ctemplate/template_annotator.h>
|
||||
|
||||
|
@ -71,10 +72,7 @@ void PerExpandData::InsertForModifiers(const char* key, const void* value) {
|
|||
// Retrieve data specific to this Expand call. Returns NULL if key
|
||||
// is not found. This should only be used by template modifiers.
|
||||
const void* PerExpandData::LookupForModifiers(const char* key) const {
|
||||
if (!map_)
|
||||
return NULL;
|
||||
const DataMap::const_iterator it = map_->find(key);
|
||||
return it == map_->end() ? NULL : it->second;
|
||||
return map_ ? find_ptr2(*map_, key) : NULL;
|
||||
}
|
||||
|
||||
_END_GOOGLE_NAMESPACE_
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
#include <config.h>
|
||||
#include "base/mutex.h" // This has to come first to get _XOPEN_SOURCE
|
||||
#include <ctemplate/find_ptr.h>
|
||||
#include <ctemplate/template_string.h>
|
||||
#include HASH_SET_H
|
||||
#include "base/arena.h"
|
||||
|
@ -173,9 +174,9 @@ void TemplateString::AddToGlobalIdToNameMap() LOCKS_EXCLUDED(mutex) {
|
|||
// Check to see if it's already here.
|
||||
ReaderMutexLock reader_lock(&mutex);
|
||||
if (template_string_set) {
|
||||
TemplateStringSet::const_iterator iter =
|
||||
template_string_set->find(*this);
|
||||
if (iter != template_string_set->end()) {
|
||||
const TemplateString* iter =
|
||||
find_ptr0(*template_string_set, *this);
|
||||
if (iter) {
|
||||
DCHECK_EQ(TemplateString(ptr_, length_),
|
||||
TemplateString(iter->ptr_, iter->length_))
|
||||
<< "TemplateId collision!";
|
||||
|
@ -193,7 +194,7 @@ void TemplateString::AddToGlobalIdToNameMap() LOCKS_EXCLUDED(mutex) {
|
|||
arena = new UnsafeArena(1024); // 1024 was picked out of a hat.
|
||||
}
|
||||
|
||||
if (template_string_set->find(*this) != template_string_set->end()) {
|
||||
if (template_string_set->count(*this)) {
|
||||
return;
|
||||
}
|
||||
// If we are immutable, we can store ourselves directly in the map.
|
||||
|
@ -225,15 +226,10 @@ TemplateString TemplateString::IdToString(TemplateId id) LOCKS_EXCLUDED(mutex) {
|
|||
// TemplateString. This may seem weird, but it lets us use a
|
||||
// hash_set instead of a hash_map.
|
||||
TemplateString id_as_template_string(NULL, 0, false, id);
|
||||
TemplateStringSet::const_iterator iter =
|
||||
template_string_set->find(id_as_template_string);
|
||||
if (iter == template_string_set->end()) {
|
||||
return TemplateString(kStsEmpty);
|
||||
}
|
||||
return *iter;
|
||||
const TemplateString* iter = find_ptr0(*template_string_set, id_as_template_string);
|
||||
return iter ? *iter : TemplateString(kStsEmpty);
|
||||
}
|
||||
|
||||
|
||||
StaticTemplateStringInitializer::StaticTemplateStringInitializer(
|
||||
const StaticTemplateString* sts) {
|
||||
// Compute the sts's id if it wasn't specified at static-init
|
||||
|
|
Loading…
Reference in New Issue
Block a user