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/msg.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/msg.hpp')
-rw-r--r-- | bindings/cpp/upb/msg.hpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/bindings/cpp/upb/msg.hpp b/bindings/cpp/upb/msg.hpp new file mode 100644 index 0000000..c7cf1f2 --- /dev/null +++ b/bindings/cpp/upb/msg.hpp @@ -0,0 +1,62 @@ +// +// upb - a minimalist implementation of protocol buffers. +// +// Copyright (c) 2011 Google Inc. See LICENSE for details. +// Author: Josh Haberman <jhaberman@gmail.com> +// Routines for reading and writing message data to an in-memory structure, +// similar to a C struct. +// +// upb does not define one single message object that everyone must use. +// Rather it defines an abstract interface for reading and writing members +// of a message object, and all of the parsers and serializers use this +// abstract interface. This allows upb's parsers and serializers to be used +// regardless of what memory management scheme or synchronization model the +// application is using. +// +// A standard set of accessors is provided for doing simple reads and writes at +// a known offset into the message. These accessors should be used when +// possible, because they are specially optimized -- for example, the JIT can +// recognize them and emit specialized code instead of having to call the +// function at all. The application can substitute its own accessors when the +// standard accessors are not suitable. + +#ifndef UPB_MSG_HPP +#define UPB_MSG_HPP + +#include "upb/msg.h" +#include "upb/handlers.hpp" + +namespace upb { + +typedef upb_accessor_vtbl AccessorVTable; + +// Registers handlers for writing into a message of the given type using +// whatever accessors it has defined. +inline MessageHandlers* RegisterWriteHandlers(upb::Handlers* handlers, + const upb::MessageDef* md) { + return MessageHandlers::Cast( + upb_accessors_reghandlers(handlers, md)); +} + +template <typename T> static FieldHandlers::ValueHandler* GetValueHandler(); + +// A handy templated function that will retrieve a value handler for a given +// C++ type. +#define GET_VALUE_HANDLER(type, ctype) \ + template <> \ + FieldHandlers::ValueHandler* GetValueHandler<ctype>() { \ + return &upb_stdmsg_set ## type; \ + } + +GET_VALUE_HANDLER(double, double); +GET_VALUE_HANDLER(float, float); +GET_VALUE_HANDLER(uint64, uint64_t); +GET_VALUE_HANDLER(uint32, uint32_t); +GET_VALUE_HANDLER(int64, int64_t); +GET_VALUE_HANDLER(int32, int32_t); +GET_VALUE_HANDLER(bool, bool); +#undef GET_VALUE_HANDLER + +} // namespace + +#endif |