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/handlers.cc | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 bindings/cpp/upb/handlers.cc (limited to 'bindings/cpp/upb/handlers.cc') diff --git a/bindings/cpp/upb/handlers.cc b/bindings/cpp/upb/handlers.cc new file mode 100644 index 0000000..c96a74e --- /dev/null +++ b/bindings/cpp/upb/handlers.cc @@ -0,0 +1,39 @@ +// +// upb - a minimalist implementation of protocol buffers. +// +// Copyright (c) 2011 Google Inc. See LICENSE for details. +// Author: Josh Haberman + +#include "handlers.hpp" + +#include "def.hpp" + +namespace upb { + +namespace { + +void MessageCallbackWrapper( + void* closure, upb_mhandlers* mh, const upb_msgdef* m) { + Handlers::MessageRegistrationVisitor* visitor = + static_cast(closure); + visitor->OnMessage(static_cast(mh), + static_cast(m)); +} + +void FieldCallbackWrapper( + void* closure, upb_fhandlers* fh, const upb_fielddef* f) { + Handlers::MessageRegistrationVisitor* visitor = + static_cast(closure); + visitor->OnField(static_cast(fh), + static_cast(f)); +} +} // namepace + +MessageHandlers* Handlers::RegisterMessageDef( + const MessageDef& m, Handlers::MessageRegistrationVisitor* visitor) { + upb_mhandlers* mh = upb_handlers_regmsgdef( + this, &m, &MessageCallbackWrapper, &FieldCallbackWrapper, &visitor); + return static_cast(mh); +} + +} // namespace upb -- cgit v1.2.3