You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2008/06/11 03:13:12 UTC

svn commit: r666472 - /incubator/thrift/trunk/lib/alterl/src/thrift_protocol.erl

Author: dreiss
Date: Tue Jun 10 18:13:12 2008
New Revision: 666472

URL: http://svn.apache.org/viewvc?rev=666472&view=rev
Log:
Optimize thrift_protocol a bit - eliminate use of a dict. gadget on a dump file runs about 15% faster

Modified:
    incubator/thrift/trunk/lib/alterl/src/thrift_protocol.erl

Modified: incubator/thrift/trunk/lib/alterl/src/thrift_protocol.erl
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/alterl/src/thrift_protocol.erl?rev=666472&r1=666471&r2=666472&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/alterl/src/thrift_protocol.erl (original)
+++ incubator/thrift/trunk/lib/alterl/src/thrift_protocol.erl Tue Jun 10 18:13:12 2008
@@ -80,13 +80,10 @@
 
 
     ok = read(IProto, struct_begin),
-    RDict = read_struct_loop(IProto, SDict, dict:new()),
+    RTuple0 = erlang:make_tuple(length(Structure), undefined),
 
-    List = [case dict:find(Index, RDict) of
-                {ok, Val} -> Val;
-                error     -> undefined
-            end || Index <- IndexList],
-    {ok, list_to_tuple(List)};
+    RTuple1 = read_struct_loop(IProto, SDict, RTuple0),
+    {ok, RTuple1};
 
 read(IProto, {struct, {Module, StructureName}}) when is_atom(Module),
                                                      is_atom(StructureName) ->
@@ -127,25 +124,25 @@
                data = ModuleData}, ProtocolType) ->
     Module:read(ModuleData, ProtocolType).
 
-read_struct_loop(IProto, SDict, RDict) ->
+read_struct_loop(IProto, SDict, RTuple) ->
     #protocol_field_begin{type = FType, id = Fid, name = Name} =
         thrift_protocol:read(IProto, field_begin),
     case {FType, Fid} of
         {?tType_STOP, _} ->
-            RDict;
+            RTuple;
         _Else ->
             case dict:find(Fid, SDict) of
                 {ok, {Type, Index}} ->
                     {ok, Val} = read(IProto, Type),
                     thrift_protocol:read(IProto, field_end),
-                    NewRDict = dict:store(Index, Val, RDict),
-                    read_struct_loop(IProto, SDict, NewRDict);
+                    NewRTuple = setelement(Index, RTuple, Val),
+                    read_struct_loop(IProto, SDict, NewRTuple);
                 _Else2 ->
                     error_logger:info_msg("Skipping fid ~p~n", [Fid]),
                     FTypeAtom = thrift_protocol:typeid_to_atom(FType),
                     thrift_protocol:skip(IProto, FTypeAtom),
                     read(IProto, field_end),
-                    read_struct_loop(IProto, SDict, RDict)
+                    read_struct_loop(IProto, SDict, RTuple)
             end
     end.