Skip to content

Commit

Permalink
inline the trivial int conversion functions in the code generator
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 486670074
  • Loading branch information
ericsalo authored and Copybara-Service committed Nov 7, 2022
1 parent f630787 commit cb7a519
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
14 changes: 1 addition & 13 deletions upb/msg_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand Down
12 changes: 4 additions & 8 deletions upbc/protoc-gen-upb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit cb7a519

Please sign in to comment.