From 3fe1dbc5e4db83c0e191e12bc16fa1fdb7109b79 Mon Sep 17 00:00:00 2001 From: Liu Liu Date: Fri, 2 Oct 2020 01:48:54 -0400 Subject: [PATCH] @mustiikhalil already have a better one to handle nil. Use that. --- app/Benchmarks/doc_mutating_generated.swift | 5 ++--- src/parser/dflatc.swift | 6 +----- src/tests/monster_mutating_generated.swift | 3 +-- src/tests/monster_v2_mutating_generated.swift | 3 +-- 4 files changed, 5 insertions(+), 12 deletions(-) diff --git a/app/Benchmarks/doc_mutating_generated.swift b/app/Benchmarks/doc_mutating_generated.swift index 81fa08779..3b2a7bbc5 100644 --- a/app/Benchmarks/doc_mutating_generated.swift +++ b/app/Benchmarks/doc_mutating_generated.swift @@ -95,9 +95,8 @@ extension BenchDoc { let __content = self.content.to(flatBufferBuilder: &flatBufferBuilder) let __tag = self.tag.map { flatBufferBuilder.create(string: $0) } ?? Offset() let start = zzz_DflatGen_BenchDoc.startBenchDoc(&flatBufferBuilder) - if let __pos = self.pos.to(flatBufferBuilder: &flatBufferBuilder) { - zzz_DflatGen_BenchDoc.add(pos: __pos, &flatBufferBuilder) - } + let __pos = self.pos.to(flatBufferBuilder: &flatBufferBuilder) + zzz_DflatGen_BenchDoc.add(pos: __pos, &flatBufferBuilder) zzz_DflatGen_BenchDoc.add(color: __color, &flatBufferBuilder) zzz_DflatGen_BenchDoc.add(title: __title, &flatBufferBuilder) zzz_DflatGen_BenchDoc.add(contentType: __contentType, &flatBufferBuilder) diff --git a/src/parser/dflatc.swift b/src/parser/dflatc.swift index b8b711eb4..03c7de5b4 100644 --- a/src/parser/dflatc.swift +++ b/src/parser/dflatc.swift @@ -647,11 +647,7 @@ func GenStructSerializer(_ structDef: Struct, code: inout String) { case .struct: let subStructDef = structDefs[field.type.struct!]! if subStructDef.fixed { - // This may be nil, in that case, we don't need to write it out at all. - code += " if let __\(field.name) = self.\(field.name).to(flatBufferBuilder: &flatBufferBuilder) {\n" - code += " \(GetDflatGenFullyQualifiedName(structDef)).add(\(field.name): __\(field.name), &flatBufferBuilder)\n" - code += " }\n" - break + code += " let __\(field.name) = self.\(field.name).to(flatBufferBuilder: &flatBufferBuilder)\n" } fallthrough case .union, .enum, .string: diff --git a/src/tests/monster_mutating_generated.swift b/src/tests/monster_mutating_generated.swift index 531c3d99f..b37761f72 100644 --- a/src/tests/monster_mutating_generated.swift +++ b/src/tests/monster_mutating_generated.swift @@ -80,9 +80,8 @@ extension MyGame.Sample.Monster { } let __vector_path = flatBufferBuilder.endVectorOfStructs(count: self.path.count) let start = zzz_DflatGen_MyGame_Sample_Monster.startMonster(&flatBufferBuilder) - if let __pos = self.pos.to(flatBufferBuilder: &flatBufferBuilder) { + let __pos = self.pos.to(flatBufferBuilder: &flatBufferBuilder) zzz_DflatGen_MyGame_Sample_Monster.add(pos: __pos, &flatBufferBuilder) - } zzz_DflatGen_MyGame_Sample_Monster.add(mana: self.mana, &flatBufferBuilder) zzz_DflatGen_MyGame_Sample_Monster.add(hp: self.hp, &flatBufferBuilder) zzz_DflatGen_MyGame_Sample_Monster.add(name: __name, &flatBufferBuilder) diff --git a/src/tests/monster_v2_mutating_generated.swift b/src/tests/monster_v2_mutating_generated.swift index 5674c347c..c8d0ce72f 100644 --- a/src/tests/monster_v2_mutating_generated.swift +++ b/src/tests/monster_v2_mutating_generated.swift @@ -128,9 +128,8 @@ extension MyGame.SampleV2.Monster { let __wearType = self.wear._type let __wear = self.wear.to(flatBufferBuilder: &flatBufferBuilder) let start = zzz_DflatGen_MyGame_SampleV2_Monster.startMonster(&flatBufferBuilder) - if let __pos = self.pos.to(flatBufferBuilder: &flatBufferBuilder) { + let __pos = self.pos.to(flatBufferBuilder: &flatBufferBuilder) zzz_DflatGen_MyGame_SampleV2_Monster.add(pos: __pos, &flatBufferBuilder) - } zzz_DflatGen_MyGame_SampleV2_Monster.add(mana: self.mana, &flatBufferBuilder) zzz_DflatGen_MyGame_SampleV2_Monster.add(hp: self.hp, &flatBufferBuilder) zzz_DflatGen_MyGame_SampleV2_Monster.add(name: __name, &flatBufferBuilder)