Refactor define::msgpack_unpack() to use 'switch' instead of several if's.

convert.benchmark test show some improvement.
This commit is contained in:
Vladimir Volodko 2013-11-20 14:02:20 +07:00 committed by Nobuyuki Kubota
parent 98c5767372
commit d47f72be0c

View File

@ -107,8 +107,15 @@ struct define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> {
{ {
if(o.type != type::ARRAY) { throw type_error(); } if(o.type != type::ARRAY) { throw type_error(); }
const size_t size = o.via.array.size; const size_t size = o.via.array.size;
<%0.upto(i) {|j|%> if(size > 0) {
if(size <= <%=j%>) { return; } o.via.array.ptr[<%=j%>].convert(&a<%=j%>);<%}%> msgpack::object *ptr = o.via.array.ptr;
switch(size) {
default:
<%(i).downto(0) {|j|%>
case <%=j+1%>: ptr[<%=j%>].convert(&a<%=j%>);<%}%>
;
}
}
} }
void msgpack_object(msgpack::object* o, msgpack::zone* z) const void msgpack_object(msgpack::object* o, msgpack::zone* z) const
{ {