Modified 'unpacked' interface using references instead of pointers.

Added speed test for 'unpacked' based unpack() function.
This commit is contained in:
Takatoshi Kondo 2013-09-04 16:53:47 +09:00
parent 521a4f4190
commit 27629a8dd6
4 changed files with 24 additions and 14 deletions

View File

@ -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;
}

View File

@ -542,8 +542,8 @@ public:
unpacked(object const& obj, msgpack::unique_ptr<msgpack::zone> 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:

View File

@ -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);

View File

@ -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<int>());
msgpack::unpack(&msg, sbuf.data(), sbuf.size(), &offset);
msgpack::unpack(msg, sbuf.data(), sbuf.size(), &offset);
EXPECT_EQ(2, msg.get().as<int>());
msgpack::unpack(&msg, sbuf.data(), sbuf.size(), &offset);
msgpack::unpack(msg, sbuf.data(), sbuf.size(), &offset);
EXPECT_EQ(3, msg.get().as<int>());
}