diff --git a/example/speed_test.cc b/example/speed_test.cc index 267c042b..589fbe40 100644 --- a/example/speed_test.cc +++ b/example/speed_test.cc @@ -36,6 +36,16 @@ void test_map_pack_unpack() { std::cout << result << std::endl; } std::cout << "Unpack finished..." << std::endl; + + msgpack::unpacked unpacked; + std::cout << "Start unpacking...by void unpack(unpacked* result, const char* data, size_t len, size_t* offset = NULL)" << std::endl; + { + boost::timer::cpu_timer timer; + msgpack::unpack(unpacked, str.data(), str.size()); + std::string result = timer.format(); + std::cout << result << std::endl; + } + std::cout << "Unpack finished..." << std::endl; } diff --git a/src/msgpack/unpack.hpp b/src/msgpack/unpack.hpp index 6b538760..694b75c4 100644 --- a/src/msgpack/unpack.hpp +++ b/src/msgpack/unpack.hpp @@ -542,8 +542,8 @@ public: unpacked(object const& obj, msgpack::unique_ptr z) : m_obj(obj), m_zone(msgpack::move(z)) { } - object& get() - { return m_obj; } + void set(object const& obj) + { m_obj = obj; } const object& get() const { return m_obj; } @@ -670,7 +670,7 @@ private: }; -static void unpack(unpacked* result, +static void unpack(unpacked& result, const char* data, size_t len, size_t* offset = NULL); @@ -824,12 +824,12 @@ inline bool unpacker::next(unpacked* result) if(ret == 0) { result->zone().reset(); - result->get() = object(); + result->set(object()); return false; } else { result->zone().reset( release_zone() ); - result->get() = data(); + result->set(data()); reset(); return true; } @@ -981,7 +981,7 @@ unpack_imp(const char* data, size_t len, size_t* off, } // detail -inline void unpack(unpacked* result, +inline void unpack(unpacked& result, const char* data, size_t len, size_t* offset) { object obj; @@ -993,13 +993,13 @@ inline void unpack(unpacked* result, switch(ret) { case UNPACK_SUCCESS: - result->get() = obj; - result->zone() = msgpack::move(z); + result.set(obj); + result.zone() = msgpack::move(z); return; case UNPACK_EXTRA_BYTES: - result->get() = obj; - result->zone() = msgpack::move(z); + result.set(obj); + result.zone() = msgpack::move(z); return; case UNPACK_CONTINUE: diff --git a/test/fixint.cc b/test/fixint.cc index 63288a1b..a45edb90 100644 --- a/test/fixint.cc +++ b/test/fixint.cc @@ -30,7 +30,7 @@ void check_convert() { msgpack::pack(sbuf, v1); msgpack::unpacked msg; - msgpack::unpack(&msg, sbuf.data(), sbuf.size()); + msgpack::unpack(msg, sbuf.data(), sbuf.size()); T v2; msg.get().convert(&v2); diff --git a/test/pack_unpack.cc b/test/pack_unpack.cc index 6718a01b..fd42bc4d 100644 --- a/test/pack_unpack.cc +++ b/test/pack_unpack.cc @@ -81,13 +81,13 @@ TEST(unpack, sequence) msgpack::unpacked msg; - msgpack::unpack(&msg, sbuf.data(), sbuf.size(), &offset); + msgpack::unpack(msg, sbuf.data(), sbuf.size(), &offset); EXPECT_EQ(1, msg.get().as()); - msgpack::unpack(&msg, sbuf.data(), sbuf.size(), &offset); + msgpack::unpack(msg, sbuf.data(), sbuf.size(), &offset); EXPECT_EQ(2, msg.get().as()); - msgpack::unpack(&msg, sbuf.data(), sbuf.size(), &offset); + msgpack::unpack(msg, sbuf.data(), sbuf.size(), &offset); EXPECT_EQ(3, msg.get().as()); }