|
@@ -107,12 +107,12 @@ class TypeInfoForTypeResolver : public TypeInfo {
|
|
|
|
|
|
virtual const google::protobuf::Field* FindField(
|
|
|
const google::protobuf::Type* type, StringPiece camel_case_name) const {
|
|
|
- if (indexed_types_.find(type) == indexed_types_.end()) {
|
|
|
- PopulateNameLookupTable(type);
|
|
|
- indexed_types_.insert(type);
|
|
|
- }
|
|
|
+ std::map<const google::protobuf::Type*,
|
|
|
+ CamelCaseNameTable>::const_iterator it = indexed_types_.find(type);
|
|
|
+ const CamelCaseNameTable& camel_case_name_table = (it == indexed_types_.end())
|
|
|
+ ? PopulateNameLookupTable(type, &indexed_types_[type]) : it->second;
|
|
|
StringPiece name =
|
|
|
- FindWithDefault(camel_case_name_table_, camel_case_name, StringPiece());
|
|
|
+ FindWithDefault(camel_case_name_table, camel_case_name, StringPiece());
|
|
|
if (name.empty()) {
|
|
|
// Didn't find a mapping. Use whatever provided.
|
|
|
name = camel_case_name;
|
|
@@ -123,6 +123,7 @@ class TypeInfoForTypeResolver : public TypeInfo {
|
|
|
private:
|
|
|
typedef util::StatusOr<const google::protobuf::Type*> StatusOrType;
|
|
|
typedef util::StatusOr<const google::protobuf::Enum*> StatusOrEnum;
|
|
|
+ typedef std::map<StringPiece, StringPiece> CamelCaseNameTable;
|
|
|
|
|
|
template <typename T>
|
|
|
static void DeleteCachedTypes(std::map<StringPiece, T>* cached_types) {
|
|
@@ -134,32 +135,35 @@ class TypeInfoForTypeResolver : public TypeInfo {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void PopulateNameLookupTable(const google::protobuf::Type* type) const {
|
|
|
+ const CamelCaseNameTable& PopulateNameLookupTable(
|
|
|
+ const google::protobuf::Type* type,
|
|
|
+ CamelCaseNameTable* camel_case_name_table) const {
|
|
|
for (int i = 0; i < type->fields_size(); ++i) {
|
|
|
const google::protobuf::Field& field = type->fields(i);
|
|
|
StringPiece name = field.name();
|
|
|
StringPiece camel_case_name = field.json_name();
|
|
|
const StringPiece* existing = InsertOrReturnExisting(
|
|
|
- &camel_case_name_table_, camel_case_name, name);
|
|
|
+ camel_case_name_table, camel_case_name, name);
|
|
|
if (existing && *existing != name) {
|
|
|
GOOGLE_LOG(WARNING) << "Field '" << name << "' and '" << *existing
|
|
|
<< "' map to the same camel case name '" << camel_case_name
|
|
|
<< "'.";
|
|
|
}
|
|
|
}
|
|
|
+ return *camel_case_name_table;
|
|
|
}
|
|
|
|
|
|
TypeResolver* type_resolver_;
|
|
|
|
|
|
// Stores string values that will be referenced by StringPieces in
|
|
|
- // cached_types_, cached_enums_ and camel_case_name_table_.
|
|
|
+ // cached_types_, cached_enums_.
|
|
|
mutable std::set<string> string_storage_;
|
|
|
|
|
|
mutable std::map<StringPiece, StatusOrType> cached_types_;
|
|
|
mutable std::map<StringPiece, StatusOrEnum> cached_enums_;
|
|
|
|
|
|
- mutable std::set<const google::protobuf::Type*> indexed_types_;
|
|
|
- mutable std::map<StringPiece, StringPiece> camel_case_name_table_;
|
|
|
+ mutable std::map<const google::protobuf::Type*,
|
|
|
+ CamelCaseNameTable> indexed_types_;
|
|
|
};
|
|
|
} // namespace
|
|
|
|