Skip to content

Commit e4c0705

Browse files
committed
Removed redundant reflection calls to improve binary decoding speed.
1 parent 8ad741f commit e4c0705

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

Codecs/Binary.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static byte TypeToId(Type type, int version)
5959
return ++i;
6060
}
6161

62-
Type IdToType(byte id)
62+
Tuple<Type, Type> IdToType(byte id)
6363
{
6464
var type_list = SupportedAttributes[EncodingVersion];
6565
bool array = false;
@@ -82,7 +82,7 @@ Type IdToType(byte id)
8282

8383
try
8484
{
85-
return array ? type_list[id].MakeListType() : type_list[id];
85+
return new Tuple<Type, Type>((array ? type_list[id].MakeListType() : type_list[id]), (array ? type_list[id] : null));
8686
}
8787
catch (IndexOutOfRangeException)
8888
{
@@ -371,14 +371,14 @@ public object DeferredDecodeAttribute(Datamodel dm, long offset)
371371

372372
object DecodeAttribute(Datamodel dm)
373373
{
374-
var type = IdToType(Reader.ReadByte());
374+
var types = IdToType(Reader.ReadByte());
375375

376-
if (!Datamodel.IsDatamodelArrayType(type))
377-
return ReadValue(dm, type, EncodingVersion < 4);
376+
if (types.Item2 == null)
377+
return ReadValue(dm, types.Item1, EncodingVersion < 4);
378378
else
379379
{
380380
var count = Reader.ReadInt32();
381-
var inner_type = Datamodel.GetArrayInnerType(type);
381+
var inner_type = types.Item2;
382382
var array = CodecUtilities.MakeList(inner_type, count);
383383

384384
foreach (var x in Enumerable.Range(0, count))
@@ -390,15 +390,14 @@ object DecodeAttribute(Datamodel dm)
390390

391391
void SkipAttribte()
392392
{
393-
var type = IdToType(Reader.ReadByte());
393+
var types = IdToType(Reader.ReadByte());
394394

395395
int count = 1;
396-
bool array = false;
397-
if (Datamodel.IsDatamodelArrayType(type))
396+
Type type = types.Item1;
397+
if (types.Item2 != null)
398398
{
399-
array = true;
400399
count = Reader.ReadInt32();
401-
type = Datamodel.GetArrayInnerType(type);
400+
type = types.Item2;
402401
}
403402

404403
if (type == typeof(Element))
@@ -424,7 +423,7 @@ void SkipAttribte()
424423
}
425424
else if (type == typeof(string))
426425
{
427-
if (!StringDict.Dummy && !array && EncodingVersion >= 4)
426+
if (!StringDict.Dummy && types.Item2 == null && EncodingVersion >= 4)
428427
length = StringDict.IndiceSize;
429428
else
430429
{

0 commit comments

Comments
 (0)