From cb7a51938c0ebdbe1de57f820b26070b952d6049 Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Mon, 7 Nov 2022 08:33:30 -0800 Subject: [PATCH] inline the trivial int conversion functions in the code generator PiperOrigin-RevId: 486670074 --- upb/msg_internal.h | 14 +------------- upbc/protoc-gen-upb.cc | 12 ++++-------- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/upb/msg_internal.h b/upb/msg_internal.h index 19ba158565..d6962afd49 100644 --- a/upb/msg_internal.h +++ b/upb/msg_internal.h @@ -51,18 +51,6 @@ extern "C" { #endif -/** upb_*Int* conversion routines ********************************************/ - -UPB_INLINE int32_t _upb_Int32_FromI(int v) { return (int32_t)v; } - -UPB_INLINE int64_t _upb_Int64_FromLL(long long v) { return (int64_t)v; } - -UPB_INLINE uint32_t _upb_UInt32_FromU(unsigned v) { return (uint32_t)v; } - -UPB_INLINE uint64_t _upb_UInt64_FromULL(unsigned long long v) { - return (uint64_t)v; -} - extern const float kUpb_FltInfinity; extern const double kUpb_Infinity; @@ -93,7 +81,7 @@ typedef enum { // Mask to isolate the upb_FieldMode from field.mode. #define kUpb_FieldMode_Mask 3 -/* Extra flags on the mode field. */ +// Extra flags on the mode field. typedef enum { kUpb_LabelFlags_IsPacked = 4, kUpb_LabelFlags_IsExtension = 8, diff --git a/upbc/protoc-gen-upb.cc b/upbc/protoc-gen-upb.cc index 7d71e2c95d..b0f82628a5 100644 --- a/upbc/protoc-gen-upb.cc +++ b/upbc/protoc-gen-upb.cc @@ -219,17 +219,13 @@ std::string FieldDefault(const protobuf::FieldDescriptor* field) { return absl::Substitute("upb_StringView_FromString(\"$0\")", absl::CEscape(field->default_value_string())); case protobuf::FieldDescriptor::CPPTYPE_INT32: - return absl::Substitute("_upb_Int32_FromI($0)", - field->default_value_int32()); + return absl::Substitute("(int32_t)$0", field->default_value_int32()); case protobuf::FieldDescriptor::CPPTYPE_INT64: - return absl::Substitute("_upb_Int64_FromLL($0ll)", - field->default_value_int64()); + return absl::Substitute("(int64_t)$0ll", field->default_value_int64()); case protobuf::FieldDescriptor::CPPTYPE_UINT32: - return absl::Substitute("_upb_UInt32_FromU($0u)", - field->default_value_uint32()); + return absl::Substitute("(uint32_t)$0u", field->default_value_uint32()); case protobuf::FieldDescriptor::CPPTYPE_UINT64: - return absl::Substitute("_upb_UInt64_FromULL($0ull)", - field->default_value_uint64()); + return absl::Substitute("(uint64_t)$0ull", field->default_value_uint64()); case protobuf::FieldDescriptor::CPPTYPE_FLOAT: return FloatToCLiteral(field->default_value_float()); case protobuf::FieldDescriptor::CPPTYPE_DOUBLE: