From 86bad61b76a260ffc442acffbe58feee67df45e5 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sat, 24 Mar 2012 11:24:16 -0700 Subject: Sync from internal Google development. Many improvements, too many to mention. One significant perf regression warrants investigation: omitfp.parsetoproto2_googlemessage1.upb_jit: 343 -> 252 (-26.53) plain.parsetoproto2_googlemessage1.upb_jit: 334 -> 251 (-24.85) 25% regression for this benchmark is bad, but since I don't think there's any fundamental design issue that caused it I'm going to go ahead with the commit anyway. Can investigate and fix later. Other benchmarks were neutral or showed slight improvement. --- bindings/cpp/upb/upb.hpp | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'bindings/cpp/upb/upb.hpp') diff --git a/bindings/cpp/upb/upb.hpp b/bindings/cpp/upb/upb.hpp index 226859c..48c2708 100644 --- a/bindings/cpp/upb/upb.hpp +++ b/bindings/cpp/upb/upb.hpp @@ -10,6 +10,16 @@ #include "upb/upb.h" #include +#if defined(__GXX_EXPERIMENTAL_CXX0X__) && !defined(UPB_NO_CXX11) +#define UPB_DISALLOW_CONSTRUCT_AND_DESTRUCT(class_name) \ + class_name() = delete; \ + ~class_name() = delete; +#else +#define UPB_DISALLOW_CONSTRUCT_AND_DESTRUCT(class_name) \ + class_name(); \ + ~class_name(); +#endif + namespace upb { typedef upb_success_t Success; @@ -31,11 +41,35 @@ class Status : public upb_status { void Clear() { upb_status_clear(this); } }; -class Value : public upb_value { - public: - Value(const upb_value& val) { *this = val; } - Value() {} -}; +typedef upb_value Value; + +template T GetValue(Value v); +template Value MakeValue(T v); + +#define UPB_VALUE_ACCESSORS(type, ctype) \ + template <> inline ctype GetValue(Value v) { \ + return upb_value_get ## type(v); \ + } \ + template <> inline Value MakeValue(ctype v) { \ + return upb_value_ ## type(v); \ + } + +UPB_VALUE_ACCESSORS(double, double); +UPB_VALUE_ACCESSORS(float, float); +UPB_VALUE_ACCESSORS(int32, int32_t); +UPB_VALUE_ACCESSORS(int64, int64_t); +UPB_VALUE_ACCESSORS(uint32, uint32_t); +UPB_VALUE_ACCESSORS(uint64, uint64_t); +UPB_VALUE_ACCESSORS(bool, bool); + +#undef UPB_VALUE_ACCESSORS + +template inline T* GetPtrValue(Value v) { + return static_cast(upb_value_getptr(v)); +} +template inline Value MakePtrValue(T* v) { + return upb_value_ptr(static_cast(v)); +} INLINE std::ostream& operator<<(std::ostream& out, const Status& status) { out << status.GetString(); -- cgit v1.2.3