Addressed PR comments.

pull/13171/head
Joshua Haberman 3 years ago
parent b11e161ebb
commit 2e141b24fc
  1. 2
      upb/def.c
  2. 2
      upb/def.h
  3. 17
      upbc/protoc-gen-upb.cc

@ -2402,7 +2402,7 @@ static int count_bits_debug(uint64_t x) {
static int compare_int32(const void* a_ptr, const void* b_ptr) { static int compare_int32(const void* a_ptr, const void* b_ptr) {
int32_t a = *(int32_t*)a_ptr; int32_t a = *(int32_t*)a_ptr;
int32_t b = *(int32_t*)b_ptr; int32_t b = *(int32_t*)b_ptr;
return ((a) < (b) ? -1 : ((a) == (b) ? 0 : 1)); return (a) < (b) ? -1 : ((a) == (b) ? 0 : 1);
} }
upb_MiniTable_Enum* create_enumlayout(symtab_addctx* ctx, upb_MiniTable_Enum* create_enumlayout(symtab_addctx* ctx,

@ -389,7 +389,7 @@ typedef struct _upb_DefPool_Init {
upb_StringView descriptor; /* Serialized descriptor. */ upb_StringView descriptor; /* Serialized descriptor. */
} _upb_DefPool_Init; } _upb_DefPool_Init;
// Should only be directly called by tests. This varant lets us suppress // Should only be directly called by tests. This variant lets us suppress
// the use of compiled-in tables, forcing a rebuild of the tables at runtime. // the use of compiled-in tables, forcing a rebuild of the tables at runtime.
bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init, bool _upb_DefPool_LoadDefInitEx(upb_DefPool* s, const _upb_DefPool_Init* init,
bool rebuild_minitable); bool rebuild_minitable);

@ -102,7 +102,8 @@ std::vector<int32_t> SortedUniqueEnumNumbers(
values.push_back(e->value(i)->number()); values.push_back(e->value(i)->number());
} }
std::sort(values.begin(), values.end()); std::sort(values.begin(), values.end());
std::unique(values.begin(), values.end()); auto last = std::unique(values.begin(), values.end());
values.erase(last, values.end());
return values; return values;
} }
@ -1311,22 +1312,20 @@ int WriteEnums(const protobuf::FileDescriptor* file, Output& output) {
for (const auto* e : this_file_enums) { for (const auto* e : this_file_enums) {
uint64_t mask = 0; uint64_t mask = 0;
absl::flat_hash_set<int32_t> values; std::vector<int32_t> values;
for (auto number : SortedUniqueEnumNumbers(e)) { for (auto number : SortedUniqueEnumNumbers(e)) {
if (static_cast<uint32_t>(number) < 64) { if (static_cast<uint32_t>(number) < 64) {
mask |= 1ULL << number; mask |= 1ULL << number;
} else { } else {
values.insert(number); values.push_back(number);
} }
} }
std::vector<int32_t> values_vec(values.begin(), values.end());
std::sort(values_vec.begin(), values_vec.end());
if (!values_vec.empty()) { if (!values.empty()) {
values_init = EnumInit(e) + "_values"; values_init = EnumInit(e) + "_values";
output("static const int32_t $0[$1] = {\n", values_init, output("static const int32_t $0[$1] = {\n", values_init,
values_vec.size()); values.size());
for (auto value : values_vec) { for (auto value : values) {
output(" $0,\n", value); output(" $0,\n", value);
} }
output("};\n\n"); output("};\n\n");
@ -1335,7 +1334,7 @@ int WriteEnums(const protobuf::FileDescriptor* file, Output& output) {
output("const upb_MiniTable_Enum $0 = {\n", EnumInit(e)); output("const upb_MiniTable_Enum $0 = {\n", EnumInit(e));
output(" $0,\n", values_init); output(" $0,\n", values_init);
output(" 0x$0ULL,\n", absl::Hex(mask)); output(" 0x$0ULL,\n", absl::Hex(mask));
output(" $0,\n", values_vec.size()); output(" $0,\n", values.size());
output("};\n\n"); output("};\n\n");
} }

Loading…
Cancel
Save