Replace ImplicitWeakMessage::_InternalParse with a TcParse table implementation.

PiperOrigin-RevId: 607000942
pull/15830/head
Protobuf Team Bot 12 months ago committed by Copybara-Service
parent 72e0be1031
commit e65e8ca900
  1. 29
      src/google/protobuf/implicit_weak_message.cc
  2. 20
      src/google/protobuf/implicit_weak_message.h

@ -7,9 +7,9 @@
#include "google/protobuf/implicit_weak_message.h"
#include "google/protobuf/io/zero_copy_stream_impl_lite.h"
#include "google/protobuf/generated_message_tctable_decl.h"
#include "google/protobuf/message_lite.h"
#include "google/protobuf/parse_context.h"
#include "google/protobuf/wire_format_lite.h"
// Must be included last.
#include "google/protobuf/port_def.inc"
@ -20,9 +20,9 @@ namespace google {
namespace protobuf {
namespace internal {
const char* ImplicitWeakMessage::_InternalParse(const char* ptr,
ParseContext* ctx) {
return ctx->AppendString(ptr, data_);
const char* ImplicitWeakMessage::ParseImpl(ImplicitWeakMessage* msg,
const char* ptr, ParseContext* ctx) {
return ctx->AppendString(ptr, msg->data_);
}
struct ImplicitWeakMessageDefaultType {
@ -42,6 +42,25 @@ const ImplicitWeakMessage* ImplicitWeakMessage::default_instance() {
&implicit_weak_message_default_instance);
}
const MessageLite::ClassData* ImplicitWeakMessage::GetClassData() const {
struct Data {
ClassData header;
char name[1];
};
static const auto table =
internal::CreateStubTcParseTable<ImplicitWeakMessage, ParseImpl>(
&implicit_weak_message_default_instance.instance);
static constexpr Data data = {
{
&table.header,
nullptr, // on_demand_register_arena_dtor
PROTOBUF_FIELD_OFFSET(ImplicitWeakMessage, cached_size_),
true,
},
""};
return &data.header;
}
} // namespace internal
} // namespace protobuf
} // namespace google

@ -56,20 +56,7 @@ class PROTOBUF_EXPORT ImplicitWeakMessage : public MessageLite {
static const ImplicitWeakMessage* default_instance();
const ClassData* GetClassData() const final {
struct Data {
ClassData header;
char name[1];
};
static constexpr Data data = {
{
nullptr, // on_demand_register_arena_dtor
PROTOBUF_FIELD_OFFSET(ImplicitWeakMessage, cached_size_),
true,
},
""};
return &data.header;
}
const ClassData* GetClassData() const final;
MessageLite* New(Arena* arena) const override {
return Arena::CreateMessage<ImplicitWeakMessage>(arena);
@ -87,8 +74,6 @@ class PROTOBUF_EXPORT ImplicitWeakMessage : public MessageLite {
}
}
const char* _InternalParse(const char* ptr, ParseContext* ctx) final;
size_t ByteSizeLong() const override {
size_t size = data_ == nullptr ? 0 : data_->size();
cached_size_.Set(internal::ToCachedSize(size));
@ -107,6 +92,9 @@ class PROTOBUF_EXPORT ImplicitWeakMessage : public MessageLite {
typedef void InternalArenaConstructable_;
private:
static const char* ParseImpl(ImplicitWeakMessage* msg, const char* ptr,
ParseContext* ctx);
// This std::string is allocated on the heap, but we use a raw pointer so that
// the default instance can be constant-initialized. In the const methods, we
// have to handle the possibility of data_ being null.

Loading…
Cancel
Save