From cf46e11af80acd7a7a7f33aab702cf96dd3a07d5 Mon Sep 17 00:00:00 2001 From: Hong Shin Date: Tue, 19 Nov 2024 12:25:51 -0800 Subject: [PATCH] Simplification: remove unused hpb::Parse invocations Too many parseses... like bagginses.. we can expand once the need arises, yess PiperOrigin-RevId: 698105703 --- hpb/hpb.h | 46 +++++++++++----------------------------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/hpb/hpb.h b/hpb/hpb.h index fbd6ed2f75..3becc509c3 100644 --- a/hpb/hpb.h +++ b/hpb/hpb.h @@ -96,27 +96,17 @@ ABSL_MUST_USE_RESULT bool Parse(Ptr message, absl::string_view bytes) { } template -ABSL_MUST_USE_RESULT bool Parse( - Ptr message, absl::string_view bytes, - const ::hpb::ExtensionRegistry& extension_registry) { - static_assert(!std::is_const_v); - upb_Message_Clear(hpb::interop::upb::GetMessage(message), - ::hpb::interop::upb::GetMiniTable(message)); - auto* arena = hpb::interop::upb::GetArena(message); - return upb_Decode(bytes.data(), bytes.size(), - hpb::interop::upb::GetMessage(message), - ::hpb::interop::upb::GetMiniTable(message), - /* extreg= */ - ::hpb::internal::GetUpbExtensions(extension_registry), - /* options= */ 0, arena) == kUpb_DecodeStatus_Ok; -} - -template -ABSL_MUST_USE_RESULT bool Parse( - T* message, absl::string_view bytes, - const ::hpb::ExtensionRegistry& extension_registry) { - static_assert(!std::is_const_v); - return Parse(Ptr(message, bytes, extension_registry)); +absl::StatusOr Parse(absl::string_view bytes, int options = 0) { + T message; + auto* arena = hpb::interop::upb::GetArena(&message); + upb_DecodeStatus status = + upb_Decode(bytes.data(), bytes.size(), message.msg(), + ::hpb::interop::upb::GetMiniTable(&message), + /* extreg= */ nullptr, /* options= */ 0, arena); + if (status == kUpb_DecodeStatus_Ok) { + return message; + } + return MessageDecodeError(status); } template @@ -132,20 +122,6 @@ ABSL_MUST_USE_RESULT bool Parse(T* message, absl::string_view bytes) { arena) == kUpb_DecodeStatus_Ok; } -template -absl::StatusOr Parse(absl::string_view bytes, int options = 0) { - T message; - auto* arena = hpb::interop::upb::GetArena(&message); - upb_DecodeStatus status = - upb_Decode(bytes.data(), bytes.size(), message.msg(), - ::hpb::interop::upb::GetMiniTable(&message), - /* extreg= */ nullptr, /* options= */ 0, arena); - if (status == kUpb_DecodeStatus_Ok) { - return message; - } - return MessageDecodeError(status); -} - template absl::StatusOr Parse(absl::string_view bytes, const ::hpb::ExtensionRegistry& extension_registry,