diff options
author | Joel Nothman <joel.nothman@gmail.com> | 2012-09-25 00:30:15 +1000 |
---|---|---|
committer | Joel Nothman <joel.nothman@gmail.com> | 2012-09-25 00:30:15 +1000 |
commit | d56e2b2c8aa1005fbac3b584cd003ba0cdece2e2 (patch) | |
tree | 46610af74cb781f5a3918420b5bd4fab131bdd4a /msgpack/unpack_template.h | |
parent | 96ed236c1d53e9ac4f3632ed82f15a1d6e0604da (diff) | |
download | msgpack-python-d56e2b2c8aa1005fbac3b584cd003ba0cdece2e2.tar.gz |
Use C++ function templating for skip()/construct()
Diffstat (limited to 'msgpack/unpack_template.h')
-rw-r--r-- | msgpack/unpack_template.h | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/msgpack/unpack_template.h b/msgpack/unpack_template.h index 5495a51..e0cf42e 100644 --- a/msgpack/unpack_template.h +++ b/msgpack/unpack_template.h @@ -95,7 +95,8 @@ msgpack_unpack_func(msgpack_unpack_object, _data)(msgpack_unpack_struct(_context } -msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const char* data, size_t len, size_t* off, int construct) +template <bool construct> +msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const char* data, size_t len, size_t* off) { assert(len >= *off); @@ -380,6 +381,8 @@ _header_again: _finish: + if (!construct) + msgpack_unpack_callback(_nil)(user, &obj); stack[0].obj = obj; ++p; ret = 1; @@ -405,13 +408,6 @@ _end: #undef construct_cb } - -#undef msgpack_unpack_func -#undef msgpack_unpack_callback -#undef msgpack_unpack_struct -#undef msgpack_unpack_object -#undef msgpack_unpack_user - #undef push_simple_value #undef push_fixed_value #undef push_variable_value @@ -419,6 +415,15 @@ _end: #undef again_fixed_trail_if_zero #undef start_container +static const execute_fn template_construct = &template_execute<true>; +static const execute_fn template_skip = &template_execute<false>; + +#undef msgpack_unpack_func +#undef msgpack_unpack_callback +#undef msgpack_unpack_struct +#undef msgpack_unpack_object +#undef msgpack_unpack_user + #undef NEXT_CS /* vim: set ts=4 sw=4 noexpandtab */ |