Skip to content

Commit

Permalink
Remove unnecessary assignment (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescourtney authored Apr 11, 2021
1 parent 18f64e4 commit 2e8ab94
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
9 changes: 8 additions & 1 deletion src/ExperimentalBenchmark/Benchmark.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
25 changes: 14 additions & 11 deletions src/FlatSharp/TypeModel/TableTypeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}}";
}
}
}

Expand Down

0 comments on commit 2e8ab94

Please sign in to comment.