From 2e8ab945abeb9e32ba68b5709340fea44d76a712 Mon Sep 17 00:00:00 2001 From: James Courtney <2636896+jamescourtney@users.noreply.github.com> Date: Sun, 11 Apr 2021 16:20:57 -0700 Subject: [PATCH] Remove unnecessary assignment (#140) --- src/ExperimentalBenchmark/Benchmark.fbs | 9 +++++++- src/FlatSharp/TypeModel/TableTypeModel.cs | 25 +++++++++++++---------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/ExperimentalBenchmark/Benchmark.fbs b/src/ExperimentalBenchmark/Benchmark.fbs index e061f026..97eccdf5 100644 --- a/src/ExperimentalBenchmark/Benchmark.fbs +++ b/src/ExperimentalBenchmark/Benchmark.fbs @@ -3,10 +3,17 @@ namespace BenchmarkCore; table SomeTable (fs_serializer) { //String:string; - Int:[int] (fs_vector:"IList"); + Int:[int] (fs_vector:"IList", id:0); + UV:[StructUnion] (id:1); + U:StructUnion (id:3); + NextToLast:ubyte (fs_forceWrite, id:5); + Last:ubyte (id:6); + ReallyLast:ubyte (id:7); //Struct:[SomeStruct] (fs_vector:"Array"); } +union StructUnion { SomeStruct, NestedStruct } + struct SomeStruct { NestedStruct:NestedStruct; Hash:[ubyte:32]; diff --git a/src/FlatSharp/TypeModel/TableTypeModel.cs b/src/FlatSharp/TypeModel/TableTypeModel.cs index 86b09513..b140ab50 100644 --- a/src/FlatSharp/TypeModel/TableTypeModel.cs +++ b/src/FlatSharp/TypeModel/TableTypeModel.cs @@ -532,18 +532,21 @@ private string GetPrepareSerializeBlock( string setVtableBlock = string.Empty; if (i == memberModel.ItemTypeModel.PhysicalLayout.Length - 1) { - if (vTableLength == this.GetVTableLength(this.MaxIndex)) + if (vTableLength > minVTableLength) { - // if this is the last element, then we don't need the 'if'. - setVtableBlock = $"vtableLength = {vTableLength};"; - } - else if (vTableLength > minVTableLength) - { - setVtableBlock = $@" - if ({vTableLength} > vtableLength) - {{ - vtableLength = {vTableLength}; - }}"; + if (vTableLength == this.GetVTableLength(this.MaxIndex)) + { + // if this is the last element, then we don't need the 'if'. + setVtableBlock = $"vtableLength = {vTableLength};"; + } + else + { + setVtableBlock = $@" + if ({vTableLength} > vtableLength) + {{ + vtableLength = {vTableLength}; + }}"; + } } }