Micro optimizations

This commit is contained in:
gfx 2010-09-15 12:50:11 +09:00
parent d86104ed5d
commit 60b36ffaa3

View File

@ -32,10 +32,13 @@ static void need(enc_t *enc, STRLEN len);
#if IVSIZE == 8 #if IVSIZE == 8
# define PACK_IV msgpack_pack_int64 # define PACK_IV msgpack_pack_int64
# define PACK_UV msgpack_pack_uint64
#elif IVSIZE == 4 #elif IVSIZE == 4
# define PACK_IV msgpack_pack_int32 # define PACK_IV msgpack_pack_int32
# define PACK_UV msgpack_pack_uint32
#elif IVSIZE == 2 #elif IVSIZE == 2
# define PACK_IV msgpack_pack_int16 # define PACK_IV msgpack_pack_int16
# define PACK_UV msgpack_pack_uint16
#else #else
# error "msgpack only supports IVSIZE = 8,4,2 environment." # error "msgpack only supports IVSIZE = 8,4,2 environment."
#endif #endif
@ -150,21 +153,21 @@ STATIC_INLINE void _msgpack_pack_sv(enc_t* const enc, SV* const sv, int const de
SvGETMAGIC(sv); SvGETMAGIC(sv);
if (SvPOKp(sv)) { if (SvPOKp(sv)) {
STRLEN len; STRLEN const len = SvCUR(sv);
char * csv = SvPV(sv, len); const char* const pv = SvPVX_const(sv);
if (s_pref_int && try_int(enc, csv, len)) { if (s_pref_int && try_int(enc, pv, len)) {
return; return;
} else { } else {
msgpack_pack_raw(enc, len); msgpack_pack_raw(enc, len);
msgpack_pack_raw_body(enc, csv, len); msgpack_pack_raw_body(enc, pv, len);
} }
} else if (SvNIOKp(sv)) { } else if (SvNIOKp(sv)) {
if(SvUOK(sv)) { if(SvUOK(sv)) {
msgpack_pack_uint32(enc, SvUV(sv)); PACK_UV(enc, SvUVX(sv));
} }
else if(SvIOKp(sv)) { else if(SvIOKp(sv)) {
PACK_IV(enc, SvIV(sv)); PACK_IV(enc, SvIVX(sv));
} }
else { else {
/* XXX long double is not supported yet. */ /* XXX long double is not supported yet. */