Remove dead branch in protobuf reflection for message fields.

Message fields can never have implicit presence, but we have logic in
ClearField that deallocates the message field and reassigns nullptr if the
field is a "proto3" field.

This snippet is the remnants of an old implementation of message field
reflection when proto3 was first introduced (when the initial idea is to use
open structs for everything). During implementation however, we ended up
preserving explicit presence behavior for message fields.

PiperOrigin-RevId: 691199008
pull/19037/head
Tony Liao 5 months ago committed by Copybara-Service
parent 25f6eabb76
commit 774a10798c
  1. 11
      src/google/protobuf/generated_message_reflection.cc

@ -1492,16 +1492,7 @@ void Reflection::ClearField(Message* message,
}
case FieldDescriptor::CPPTYPE_MESSAGE:
if (schema_.HasBitIndex(field) == static_cast<uint32_t>(-1)) {
// Proto3 does not have has-bits and we need to set a message field
// to nullptr in order to indicate its un-presence.
if (message->GetArena() == nullptr) {
delete *MutableRaw<Message*>(message, field);
}
*MutableRaw<Message*>(message, field) = nullptr;
} else {
(*MutableRaw<Message*>(message, field))->Clear();
}
(*MutableRaw<Message*>(message, field))->Clear();
break;
}
}

Loading…
Cancel
Save