When the compiler is gcc, use memcpy, otherwise use an assignment operator.

The memcpy approach is a workaround for gcc's bug. The speed performance on gcc is the same between both approach. But on clang, the memcpy approach is 10% slower than an assignment approach. Hence I added the switching approach code using compiler checked macro.

Note: __GNUC__ is defined both gcc and clang. So I use __GNUC__ && !__clang__
This commit is contained in:
Takatoshi Kondo 2013-12-16 13:09:57 +09:00
parent 3e2ae7cc78
commit b774c07d19

View File

@ -112,7 +112,11 @@ static inline int template_callback_array(unpack_user* u, unsigned int n, msgpac
static inline int template_callback_array_item(unpack_user* u, msgpack_object* c, msgpack_object o)
{
#if defined(__GNUC__) && !defined(__clang__)
memcpy(&c->via.array.ptr[c->via.array.size], &o, sizeof(msgpack_object));
#else /* __GNUC__ && !__clang__ */
c->via.array.ptr[c->via.array.size] = o;
#endif /* __GNUC__ && !__clang__ */
++c->via.array.size;
return 0;
}
@ -128,8 +132,13 @@ static inline int template_callback_map(unpack_user* u, unsigned int n, msgpack_
static inline int template_callback_map_item(unpack_user* u, msgpack_object* c, msgpack_object k, msgpack_object v)
{
#if defined(__GNUC__) && !defined(__clang__)
memcpy(&c->via.map.ptr[c->via.map.size].key, &k, sizeof(msgpack_object));
memcpy(&c->via.map.ptr[c->via.map.size].val, &v, sizeof(msgpack_object));
#else /* __GNUC__ && !__clang__ */
c->via.map.ptr[c->via.map.size].key = k;
c->via.map.ptr[c->via.map.size].val = v;
#endif /* __GNUC__ && !__clang__ */
++c->via.map.size;
return 0;
}