diff options
author | Joshua Haberman <jhaberman@gmail.com> | 2012-03-24 11:24:16 -0700 |
---|---|---|
committer | Joshua Haberman <jhaberman@gmail.com> | 2012-03-24 11:24:16 -0700 |
commit | 86bad61b76a260ffc442acffbe58feee67df45e5 (patch) | |
tree | e375e62ff6d7fea9fb810830e66118e67b4ec2c8 /bindings/cpp/upb/upb.hpp | |
parent | db59a5198f890ecdcac1227b0bb998160acac5c6 (diff) |
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.
Diffstat (limited to 'bindings/cpp/upb/upb.hpp')
-rw-r--r-- | bindings/cpp/upb/upb.hpp | 44 |
1 files changed, 39 insertions, 5 deletions
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 <iostream> +#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 <typename T> T GetValue(Value v); +template <typename T> Value MakeValue(T v); + +#define UPB_VALUE_ACCESSORS(type, ctype) \ + template <> inline ctype GetValue<ctype>(Value v) { \ + return upb_value_get ## type(v); \ + } \ + template <> inline Value MakeValue<ctype>(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 <typename T> inline T* GetPtrValue(Value v) { + return static_cast<T*>(upb_value_getptr(v)); +} +template <typename T> inline Value MakePtrValue(T* v) { + return upb_value_ptr(static_cast<void*>(v)); +} INLINE std::ostream& operator<<(std::ostream& out, const Status& status) { out << status.GetString(); |