mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-26 11:46:34 +01:00
erlang: Remove unecessary 'throw(short)' clause for unpack_{array,map}_/1
Unecessary because unpack_/1 will throw it anyway. This does mean that we go a tiny bit deeper to find that we don't have enough data, but that should be a rare code path. Keep the main code path fast and the code clean. While at it, rename vars to match its sibling function and to avoid thinking that RestLen is a byte count (it's an item count).
This commit is contained in:
parent
6abc120279
commit
ba4a971bfa
@ -178,11 +178,10 @@ pack_array_([Head|Tail], Acc) ->
|
|||||||
pack_array_(Tail, <<Acc/binary, (pack_(Head))/binary>>).
|
pack_array_(Tail, <<Acc/binary, (pack_(Head))/binary>>).
|
||||||
|
|
||||||
% Users SHOULD NOT send too long list: this uses lists:reverse/1
|
% Users SHOULD NOT send too long list: this uses lists:reverse/1
|
||||||
unpack_array_(Remain, 0, Acc) -> {lists:reverse(Acc), Remain};
|
unpack_array_(Bin, 0, Acc) -> {lists:reverse(Acc), Bin};
|
||||||
unpack_array_(<<>>, RestLen, _) -> throw(short);
|
unpack_array_(Bin, Len, Acc) ->
|
||||||
unpack_array_(Bin, RestLen, Acc) ->
|
{Term, Rest} = unpack_(Bin),
|
||||||
{Term, Rest}=unpack_(Bin),
|
unpack_array_(Rest, Len-1, [Term|Acc]).
|
||||||
unpack_array_(Rest, RestLen-1, [Term|Acc]).
|
|
||||||
|
|
||||||
pack_map_([], Acc) -> Acc;
|
pack_map_([], Acc) -> Acc;
|
||||||
pack_map_([{Key,Value}|Tail], Acc) ->
|
pack_map_([{Key,Value}|Tail], Acc) ->
|
||||||
@ -191,14 +190,13 @@ pack_map_([{Key,Value}|Tail], Acc) ->
|
|||||||
% Users SHOULD NOT send too long list: this uses lists:reverse/1
|
% Users SHOULD NOT send too long list: this uses lists:reverse/1
|
||||||
-spec unpack_map_(binary(), non_neg_integer(), [{msgpack_term(), msgpack_term()}])->
|
-spec unpack_map_(binary(), non_neg_integer(), [{msgpack_term(), msgpack_term()}])->
|
||||||
{[{msgpack_term(), msgpack_term()}], binary()} | no_return().
|
{[{msgpack_term(), msgpack_term()}], binary()} | no_return().
|
||||||
unpack_map_(Bin, 0, Acc) -> {{lists:reverse(Acc)}, Bin};
|
unpack_map_(Bin, 0, Acc) -> {{lists:reverse(Acc)}, Bin};
|
||||||
unpack_map_(<<>>, _, _ ) -> throw(short);
|
|
||||||
unpack_map_(Bin, Len, Acc) ->
|
unpack_map_(Bin, Len, Acc) ->
|
||||||
{Key, Rest} = unpack_(Bin),
|
{Key, Rest} = unpack_(Bin),
|
||||||
{Value, Rest2} = unpack_(Rest),
|
{Value, Rest2} = unpack_(Rest),
|
||||||
unpack_map_(Rest2,Len-1,[{Key,Value}|Acc]).
|
unpack_map_(Rest2, Len-1, [{Key,Value}|Acc]).
|
||||||
|
|
||||||
% unpack then all
|
% unpack them all
|
||||||
-spec unpack_(Bin::binary()) -> {msgpack_term(), binary()} | {error, reason()} | no_return().
|
-spec unpack_(Bin::binary()) -> {msgpack_term(), binary()} | {error, reason()} | no_return().
|
||||||
unpack_(Bin) ->
|
unpack_(Bin) ->
|
||||||
case Bin of
|
case Bin of
|
||||||
|
Loading…
x
Reference in New Issue
Block a user