mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-18 23:38:55 +00:00
[Swift] Rebuild the way swift handles structs from scratch (#6326)
* Rebuild the way swift handles structs from scratch * Updates docs, and sample binary * Replaces InMemory to Mutable * Migrates docs from inmemory * use inline for some functions * Renamed Mutable objects * Updates documentation
This commit is contained in:
@@ -89,14 +89,11 @@ func benchmarkThreeMillionStructs() {
|
||||
|
||||
var offsets: [Offset<UOffset>] = []
|
||||
for _ in 0..<structCount {
|
||||
fb.startVectorOfStructs(count: 5, size: 16, alignment: 8)
|
||||
fb.startVector(5 * MemoryLayout<AA>.size, elementSize: MemoryLayout<AA>.alignment)
|
||||
for _ in 0..<5 {
|
||||
fb.createStructOf(size: 16, alignment: 8)
|
||||
fb.reverseAdd(v: 2.4, postion: 0)
|
||||
fb.reverseAdd(v: 2.4, postion: 8)
|
||||
fb.endStruct()
|
||||
_ = fb.create(struct: AA(a: 2.4, b: 2.4))
|
||||
}
|
||||
let vector = fb.endVectorOfStructs(count: 5)
|
||||
let vector = fb.endVector(len: 5)
|
||||
let start = fb.startTable(with: 1)
|
||||
fb.add(offset: vector, at: 4)
|
||||
offsets.append(Offset<UOffset>(offset: fb.endTable(at: start)))
|
||||
@@ -108,6 +105,17 @@ func benchmarkThreeMillionStructs() {
|
||||
fb.finish(offset: root)
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
struct AA: NativeStruct {
|
||||
public init(a: Double, b: Double) {
|
||||
self.a = a
|
||||
self.b = b
|
||||
}
|
||||
var a: Double
|
||||
var b: Double
|
||||
|
||||
}
|
||||
|
||||
func benchmark(numberOfRuns runs: Int) {
|
||||
var benchmarks: [Benchmark] = []
|
||||
let str = (0...99).map { _ -> String in "x" }.joined()
|
||||
|
||||
Reference in New Issue
Block a user