Move the hook for RawMessage::SpaceUsedLong into ClassData to remove the

virtual function.

PiperOrigin-RevId: 625319013
pull/16505/head
Protobuf Team Bot 7 months ago committed by Copybara-Service
parent 5c7a9fd997
commit 9ca7354815
  1. 14
      src/google/protobuf/message.cc
  2. 8
      src/google/protobuf/message.h
  3. 1
      src/google/protobuf/message_lite.h

@ -185,13 +185,7 @@ size_t Message::MaybeComputeUnknownFieldsSize(
} }
size_t Message::SpaceUsedLong() const { size_t Message::SpaceUsedLong() const {
auto* reflection = GetReflection(); return GetClassData()->full().descriptor_methods->space_used_long(*this);
if (PROTOBUF_PREDICT_TRUE(reflection != nullptr)) {
return reflection->SpaceUsedLong(*this);
}
// The only case that does not have reflection is RawMessage.
return internal::DownCast<const internal::RawMessageBase&>(*this)
.SpaceUsedLong();
} }
static std::string GetTypeNameImpl(const MessageLite& msg) { static std::string GetTypeNameImpl(const MessageLite& msg) {
@ -207,11 +201,17 @@ const internal::TcParseTableBase* Message::GetTcParseTableImpl(
return DownCast<const Message&>(msg).GetReflection()->GetTcParseTable(); return DownCast<const Message&>(msg).GetReflection()->GetTcParseTable();
} }
size_t Message::SpaceUsedLongImpl(const MessageLite& msg_lite) {
auto& msg = DownCast<const Message&>(msg_lite);
return msg.GetReflection()->SpaceUsedLong(msg);
}
PROTOBUF_CONSTINIT const MessageLite::DescriptorMethods PROTOBUF_CONSTINIT const MessageLite::DescriptorMethods
Message::kDescriptorMethods = { Message::kDescriptorMethods = {
GetTypeNameImpl, GetTypeNameImpl,
InitializationErrorStringImpl, InitializationErrorStringImpl,
GetTcParseTableImpl, GetTcParseTableImpl,
SpaceUsedLongImpl,
}; };
namespace internal { namespace internal {

@ -386,6 +386,8 @@ class PROTOBUF_EXPORT Message : public MessageLite {
static const internal::TcParseTableBase* GetTcParseTableImpl( static const internal::TcParseTableBase* GetTcParseTableImpl(
const MessageLite& msg); const MessageLite& msg);
static size_t SpaceUsedLongImpl(const MessageLite& msg_lite);
static const DescriptorMethods kDescriptorMethods; static const DescriptorMethods kDescriptorMethods;
}; };
@ -1629,12 +1631,6 @@ bool SplitFieldHasExtraIndirectionStatic(const FieldDescriptor* field) {
return SplitFieldHasExtraIndirection(field); return SplitFieldHasExtraIndirection(field);
} }
class RawMessageBase : public Message {
public:
using Message::Message;
virtual size_t SpaceUsedLong() const = 0;
};
inline void MaybePoisonAfterClear(Message* root) { inline void MaybePoisonAfterClear(Message* root) {
if (root == nullptr) return; if (root == nullptr) return;
#ifndef PROTOBUF_ASAN #ifndef PROTOBUF_ASAN

@ -537,6 +537,7 @@ class PROTOBUF_EXPORT MessageLite {
std::string (*get_type_name)(const MessageLite&); std::string (*get_type_name)(const MessageLite&);
std::string (*initialization_error_string)(const MessageLite&); std::string (*initialization_error_string)(const MessageLite&);
const internal::TcParseTableBase* (*get_tc_table)(const MessageLite&); const internal::TcParseTableBase* (*get_tc_table)(const MessageLite&);
size_t (*space_used_long)(const MessageLite&);
}; };
struct ClassDataFull; struct ClassDataFull;
// Note: The order of arguments in the functions is chosen so that it has // Note: The order of arguments in the functions is chosen so that it has

Loading…
Cancel
Save