bulk code format fix (#8707)

This commit is contained in:
Derek Bailey
2025-09-23 21:50:27 -07:00
committed by GitHub
parent 0e047869da
commit caf3b494db
559 changed files with 38871 additions and 31276 deletions

View File

@@ -14,12 +14,12 @@
* limitations under the License.
*/
#if canImport(Common)
import Common
#endif
import Foundation
#if canImport(Common)
import Common
#endif
/// ``FlatBufferBuilder`` builds a `FlatBuffer` through manipulating its internal state.
///
/// This is done by creating a ``ByteBuffer`` that hosts the incoming data and
@@ -63,21 +63,21 @@ public struct FlatBufferBuilder {
public var capacity: Int { _bb.capacity }
#if !os(WASI)
/// Data representation of the buffer
///
/// Should only be used after ``finish(offset:addPrefix:)`` is called
public var data: Data {
assert(finished, "Data shouldn't be called before finish()")
return _bb.withUnsafeSlicedBytes { ptr in
var data = Data()
data.append(
ptr.baseAddress!.bindMemory(
to: UInt8.self,
capacity: ptr.count),
count: ptr.count)
return data
/// Data representation of the buffer
///
/// Should only be used after ``finish(offset:addPrefix:)`` is called
public var data: Data {
assert(finished, "Data shouldn't be called before finish()")
return _bb.withUnsafeSlicedBytes { ptr in
var data = Data()
data.append(
ptr.baseAddress!.bindMemory(
to: UInt8.self,
capacity: ptr.count),
count: ptr.count)
return data
}
}
}
#endif
/// Returns the underlying bytes in the ``ByteBuffer``
@@ -132,8 +132,8 @@ public struct FlatBufferBuilder {
/// however the builder can be force by passing true for `serializeDefaults`
public init(
initialSize: Int32 = 1024,
serializeDefaults force: Bool = false)
{
serializeDefaults force: Bool = false
) {
assert(initialSize > 0, "Size should be greater than zero!")
guard isLitteEndian else {
fatalError(
@@ -200,8 +200,8 @@ public struct FlatBufferBuilder {
mutating public func finish(
offset: Offset,
fileId: String,
addPrefix prefix: Bool = false)
{
addPrefix prefix: Bool = false
) {
let size = MemoryLayout<UOffset>.size
preAlign(
len: size &+ (prefix ? size : 0) &+ FileIdLength,
@@ -230,8 +230,8 @@ public struct FlatBufferBuilder {
/// include the size of the current buffer.
mutating public func finish(
offset: Offset,
addPrefix prefix: Bool = false)
{
addPrefix prefix: Bool = false
) {
notNested()
let size = MemoryLayout<UOffset>.size
preAlign(len: size &+ (prefix ? size : 0), alignment: _minAlignment)
@@ -355,9 +355,11 @@ public struct FlatBufferBuilder {
@usableFromInline
mutating internal func preAlign(len: Int, alignment: Int) {
minAlignment(size: alignment)
_bb.fill(padding: numericCast(padding(
bufSize: numericCast(_bb.size) &+ numericCast(len),
elementSize: numericCast(alignment))))
_bb.fill(
padding: numericCast(
padding(
bufSize: numericCast(_bb.size) &+ numericCast(len),
elementSize: numericCast(alignment))))
}
/// Prealigns the buffer before writting a new object into the buffer
@@ -468,8 +470,8 @@ public struct FlatBufferBuilder {
@inline(__always)
mutating public func createVector<T: Scalar>(
_ elements: [T],
size: Int) -> Offset
{
size: Int
) -> Offset {
let size = size
startVector(size, elementSize: MemoryLayout<T>.size)
_bb.push(elements: elements)
@@ -477,20 +479,20 @@ public struct FlatBufferBuilder {
}
#if swift(>=5.0) && !os(WASI)
@inline(__always)
/// Creates a vector of bytes in the buffer.
///
/// Allows creating a vector from `Data` without copying to a `[UInt8]`
///
/// - Parameter bytes: bytes to be written into the buffer
/// - Returns: ``Offset`` of the vector
mutating public func createVector(bytes: ContiguousBytes) -> Offset {
bytes.withUnsafeBytes {
startVector($0.count, elementSize: MemoryLayout<UInt8>.size)
_bb.push(bytes: $0)
return endVector(len: $0.count)
@inline(__always)
/// Creates a vector of bytes in the buffer.
///
/// Allows creating a vector from `Data` without copying to a `[UInt8]`
///
/// - Parameter bytes: bytes to be written into the buffer
/// - Returns: ``Offset`` of the vector
mutating public func createVector(bytes: ContiguousBytes) -> Offset {
bytes.withUnsafeBytes {
startVector($0.count, elementSize: MemoryLayout<UInt8>.size)
_bb.push(bytes: $0)
return endVector(len: $0.count)
}
}
}
#endif
/// Creates a vector of type ``Enum`` into the ``ByteBuffer``
@@ -528,8 +530,8 @@ public struct FlatBufferBuilder {
@inline(__always)
mutating public func createVector<T: Enum>(
_ elements: [T],
size: Int) -> Offset
{
size: Int
) -> Offset {
let size = size
startVector(size, elementSize: T.byteSize)
for index in stride(from: elements.count, to: 0, by: -1) {
@@ -574,8 +576,8 @@ public struct FlatBufferBuilder {
@inline(__always)
mutating public func createVector(
ofOffsets offsets: [Offset],
len: Int) -> Offset
{
len: Int
) -> Offset {
startVector(len, elementSize: MemoryLayout<Offset>.size)
for index in stride(from: offsets.count, to: 0, by: -1) {
push(element: offsets[index &- 1])
@@ -651,8 +653,8 @@ public struct FlatBufferBuilder {
@inline(__always)
@discardableResult
mutating public func create<T: NativeStruct>(
struct s: T, position: VOffset) -> Offset
{
struct s: T, position: VOffset
) -> Offset {
let offset = create(struct: s)
_vtableStorage.add(
loc: (offset: _bb.size, position: VOffset(position)))
@@ -676,8 +678,8 @@ public struct FlatBufferBuilder {
@inline(__always)
@discardableResult
mutating public func create<T: NativeStruct>(
struct s: T) -> Offset
{
struct s: T
) -> Offset {
let size = MemoryLayout<T>.size
preAlign(len: size, alignment: MemoryLayout<T>.alignment)
_bb.push(struct: s, size: size)
@@ -792,8 +794,8 @@ public struct FlatBufferBuilder {
mutating public func add<T: Scalar>(
element: T,
def: T,
at position: VOffset)
{
at position: VOffset
) {
if element == def && !serializeDefaults { return }
track(offset: push(element: element), at: position)
}