Skip to content

Commit

Permalink
@mustiikhalil already have a better one to handle nil. Use that.
Browse files Browse the repository at this point in the history
  • Loading branch information
liuliu committed Oct 2, 2020
1 parent a123187 commit 3fe1dbc
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 12 deletions.
5 changes: 2 additions & 3 deletions app/Benchmarks/doc_mutating_generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ extension BenchDoc {
let __content = self.content.to(flatBufferBuilder: &flatBufferBuilder)
let __tag = self.tag.map { flatBufferBuilder.create(string: $0) } ?? Offset<String>()
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)
Expand Down
6 changes: 1 addition & 5 deletions src/parser/dflatc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions src/tests/monster_mutating_generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions src/tests/monster_v2_mutating_generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3fe1dbc

Please sign in to comment.