Fixed dense_below logic to be order-independent and consistent between def.c and codegen.

pull/13171/head
Joshua Haberman 4 years ago
parent 2e8a122fc0
commit 807e7fe9e2
  1. 3
      upb/def.c
  2. 11
      upbc/protoc-gen-upb.cc

@ -1027,7 +1027,8 @@ static void assign_layout_indices(const upb_msgdef *m, upb_msglayout *l,
upb_fielddef *f = (upb_fielddef*)upb_msgdef_itof(m, fields[i].number);
UPB_ASSERT(f);
f->layout_index = i;
if (i < UINT8_MAX && upb_fielddef_number(f) == i + 1) {
if (i < UINT8_MAX && fields[i].number == i + 1 &&
(i == 0 || fields[i-1].number == i)) {
dense_below = i + 1;
}
}

@ -868,6 +868,7 @@ void WriteSource(const protobuf::FileDescriptor* file, Output& output,
std::string fields_array_ref = "NULL";
std::string submsgs_array_ref = "NULL";
uint8_t dense_below = 0;
int dense_below_max = std::numeric_limits<decltype(dense_below)>::max();
MessageLayout layout(message);
SubmsgArray submsg_array(message);
@ -893,14 +894,14 @@ void WriteSource(const protobuf::FileDescriptor* file, Output& output,
fields_array_ref = "&" + fields_array_name + "[0]";
output("static const upb_msglayout_field $0[$1] = {\n",
fields_array_name, field_number_order.size());
for (auto field : field_number_order) {
for (int i = 0; i < static_cast<int>(field_number_order.size()); i++) {
auto field = field_number_order[i];
int submsg_index = 0;
std::string presence = "0";
if (field->number() <=
std::numeric_limits<decltype(dense_below)>::max() &&
dense_below + 1 == field->number()) {
dense_below = field->number();
if (i < dense_below_max && field->number() == i + 1 &&
(i == 0 || field_number_order[i - 1]->number() == i)) {
dense_below = i + 1;
}
if (field->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_MESSAGE) {

Loading…
Cancel
Save