diff options
Diffstat (limited to 'upbc/message_layout.cc')
-rw-r--r-- | upbc/message_layout.cc | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/upbc/message_layout.cc b/upbc/message_layout.cc index b6614f0..f0a6872 100644 --- a/upbc/message_layout.cc +++ b/upbc/message_layout.cc @@ -30,16 +30,20 @@ bool MessageLayout::HasHasbit(const protobuf::FieldDescriptor* field) { MessageLayout::SizeAndAlign MessageLayout::SizeOf( const protobuf::FieldDescriptor* field) { - if (field->label() == protobuf::FieldDescriptor::LABEL_REPEATED || - field->cpp_type() == protobuf::FieldDescriptor::CPPTYPE_MESSAGE) { - return {{4, 8}, {4, 8}}; + if (field->is_repeated()) { + return {{4, 8}, {4, 8}}; // Pointer to array object. + } else { + return SizeOfUnwrapped(field); } +} +MessageLayout::SizeAndAlign MessageLayout::SizeOfUnwrapped( + const protobuf::FieldDescriptor* field) { switch (field->cpp_type()) { + case protobuf::FieldDescriptor::CPPTYPE_MESSAGE: + return {{4, 8}, {4, 8}}; // Pointer to message. case protobuf::FieldDescriptor::CPPTYPE_STRING: - // upb_stringview - // return {{8, 16}, {4, 8}}; - return {{8, 16}, {8, 16}}; + return {{8, 16}, {4, 8}}; // upb_stringview case protobuf::FieldDescriptor::CPPTYPE_BOOL: return {{1, 1}, {1, 1}}; case protobuf::FieldDescriptor::CPPTYPE_FLOAT: @@ -126,7 +130,9 @@ void MessageLayout::PlaceNonOneofFields( int hasbit_count = 0; for (auto field : field_order) { if (HasHasbit(field)) { - hasbit_indexes_[field] = hasbit_count++; + // We don't use hasbit 0, so that 0 can indicate "no presence" in the + // table. This wastes one hasbit, but we don't worry about it for now. + hasbit_indexes_[field] = ++hasbit_count; } } |