@ -41,9 +41,9 @@
# include <map>
# include <memory>
# include <queue>
# include <unordered_set>
# include <vector>
# include "absl/container/flat_hash_set.h"
# include <google/protobuf/stubs/common.h>
# include <google/protobuf/stubs/logging.h>
# include <google/protobuf/descriptor.h>
@ -176,15 +176,17 @@ static const char* const kKeywordList[] = {
# endif // !PROTOBUF_FUTURE_BREAKING_CHANGES
} ;
static std : : unordered_set < std : : string > * MakeKeywordsMap ( ) {
auto * result = new std : : unordered_set < std : : string > ( ) ;
for ( const auto keyword : kKeywordList ) {
result - > emplace ( keyword ) ;
}
return result ;
}
const absl : : flat_hash_set < std : : string > & Keywords ( ) {
static const auto * keywords = [ ] {
auto * keywords = new absl : : flat_hash_set < std : : string > ( ) ;
static std : : unordered_set < std : : string > & kKeywords = * MakeKeywordsMap ( ) ;
for ( const auto keyword : kKeywordList ) {
keywords - > emplace ( keyword ) ;
}
return keywords ;
} ( ) ;
return * keywords ;
}
std : : string IntTypeName ( const Options & options , const std : : string & type ) {
return type + " _t " ;
@ -509,7 +511,7 @@ std::string SuperClassName(const Descriptor* descriptor,
}
std : : string ResolveKeyword ( const std : : string & name ) {
if ( k Keywords. count ( name ) > 0 ) {
if ( Keywords ( ) . count ( name ) > 0 ) {
return name + " _ " ;
}
return name ;
@ -518,7 +520,7 @@ std::string ResolveKeyword(const std::string& name) {
std : : string FieldName ( const FieldDescriptor * field ) {
std : : string result = field - > name ( ) ;
LowerString ( & result ) ;
if ( k Keywords. count ( result ) > 0 ) {
if ( Keywords ( ) . count ( result ) > 0 ) {
result . append ( " _ " ) ;
}
return result ;
@ -552,7 +554,7 @@ std::string QualifiedOneofCaseConstantName(const FieldDescriptor* field) {
std : : string EnumValueName ( const EnumValueDescriptor * enum_value ) {
std : : string result = enum_value - > name ( ) ;
if ( k Keywords. count ( result ) > 0 ) {
if ( Keywords ( ) . count ( result ) > 0 ) {
result . append ( " _ " ) ;
}
return result ;
@ -863,7 +865,7 @@ std::string SafeFunctionName(const Descriptor* descriptor,
// Single underscore will also make it conflicting with the private data
// member. We use double underscore to escape function names.
function_name . append ( " __ " ) ;
} else if ( k Keywords. count ( name ) > 0 ) {
} else if ( Keywords ( ) . count ( name ) > 0 ) {
// If the field name is a keyword, we append the underscore back to keep it
// consistent with other function names.
function_name . append ( " _ " ) ;
@ -1116,7 +1118,7 @@ bool IsAnyMessage(const Descriptor* descriptor, const Options& options) {
}
bool IsWellKnownMessage ( const FileDescriptor * file ) {
static const std : : unordered_set < std : : string > well_known_files {
static const auto * well_known_files = new absl : : flat_hash_set < std : : string > {
" google/protobuf/any.proto " ,
" google/protobuf/api.proto " ,
" google/protobuf/compiler/plugin.proto " ,
@ -1130,7 +1132,7 @@ bool IsWellKnownMessage(const FileDescriptor* file) {
" google/protobuf/type.proto " ,
" google/protobuf/wrappers.proto " ,
} ;
return well_known_files . find ( file - > name ( ) ) ! = well_known_files . end ( ) ;
return well_known_files - > find ( file - > name ( ) ) ! = well_known_files - > end ( ) ;
}
static void GenerateUtf8CheckCode ( const FieldDescriptor * field ,