mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-05 10:37:03 +00:00
swift 6.0+ performance tweaks 3x-6x (#9067)
* start/stop measurements * tweaks * add 6.0 annotations * remove some inlines * address feedback * address wasi + let * adopt flex buffers * flex buffers benchmarks
This commit is contained in:
@@ -47,7 +47,8 @@ public struct FlatBufferBuilder {
|
||||
/// A check to see if finish(::) was ever called to retreive data object
|
||||
private(set) var finished = false
|
||||
/// A check to see if the buffer should serialize Default values
|
||||
private var serializeDefaults: Bool
|
||||
@usableFromInline
|
||||
let serializeDefaults: Bool
|
||||
|
||||
/// Current alignment for the buffer
|
||||
var _minAlignment: Int = 0 {
|
||||
@@ -756,6 +757,7 @@ public struct FlatBufferBuilder {
|
||||
/// - offset: ``Offset`` of another object to be written
|
||||
/// - position: The predefined position of the object
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
mutating public func add(offset: Offset, at position: VOffset) {
|
||||
if offset.isEmpty { return }
|
||||
add(element: refer(to: offset.o), def: 0, at: position)
|
||||
@@ -794,6 +796,7 @@ public struct FlatBufferBuilder {
|
||||
/// - def: Default value for that element
|
||||
/// - position: The predefined position of the element
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
mutating public func add<T: Scalar>(
|
||||
element: T,
|
||||
def: T,
|
||||
@@ -813,6 +816,7 @@ public struct FlatBufferBuilder {
|
||||
/// - element: Optional element of type scalar
|
||||
/// - position: The predefined position of the element
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
mutating public func add<T: Scalar>(element: T?, at position: VOffset) {
|
||||
guard let element = element else { return }
|
||||
track(offset: push(element: element), at: position)
|
||||
@@ -825,6 +829,7 @@ public struct FlatBufferBuilder {
|
||||
/// - Parameter element: Element to insert
|
||||
/// - returns: position of the Element
|
||||
@inline(__always)
|
||||
@inlinable
|
||||
@discardableResult
|
||||
mutating public func push<T: Scalar>(element: T) -> UOffset {
|
||||
let size = MemoryLayout<T>.size
|
||||
@@ -836,7 +841,8 @@ public struct FlatBufferBuilder {
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
public func read<T>(def: T.Type, position: Int) -> T {
|
||||
@inlinable
|
||||
public func read<T: BitwiseCopyable>(def: T.Type, position: Int) -> T {
|
||||
_bb.read(def: def, position: position)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user