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
private let twentyFourBytes: Int = 24
public typealias FlexBuffersWriterBuilder = (inout FlexBuffersWriter) -> Void
@@ -74,21 +74,21 @@ public struct FlexBuffersWriter {
}
#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
/// Resets the internal state. Automatically called before building a new flexbuffer.
@@ -139,8 +139,8 @@ public struct FlexBuffersWriter {
public mutating func endVector(
start: Int,
typed: Bool = false,
fixed: Bool = false) -> UInt64
{
fixed: Bool = false
) -> UInt64 {
let vec = createVector(
start: start,
count: stack.count &- start,
@@ -162,8 +162,7 @@ public struct FlexBuffersWriter {
@discardableResult
@inline(__always)
public mutating func create<T>(vector: [T], key: borrowing String) -> Int
where T: Scalar
{
where T: Scalar {
add(key: key)
return create(vector: vector, fixed: false)
}
@@ -179,8 +178,8 @@ public struct FlexBuffersWriter {
@inline(__always)
public mutating func createFixed<T>(
vector: [T],
key: borrowing String) -> Int where T: Scalar
{
key: borrowing String
) -> Int where T: Scalar {
assert(vector.count >= 2 && vector.count <= 4)
add(key: key)
return create(vector: vector, fixed: true)
@@ -302,8 +301,8 @@ public struct FlexBuffersWriter {
@inline(__always)
public mutating func add(
uint64 value: borrowing UInt64,
key: borrowing String)
{
key: borrowing String
) {
add(key: key)
add(uint64: value)
}
@@ -316,8 +315,8 @@ public struct FlexBuffersWriter {
@inline(__always)
public mutating func indirect(
uint64 val: borrowing UInt64,
key: borrowing String)
{
key: borrowing String
) {
add(key: key)
indirect(uint64: val)
}
@@ -325,8 +324,8 @@ public struct FlexBuffersWriter {
@inline(__always)
public mutating func indirect(
uint val: borrowing UInt,
key: borrowing String)
{
key: borrowing String
) {
add(key: key)
indirect(uint64: numericCast(val))
}
@@ -385,8 +384,8 @@ public struct FlexBuffersWriter {
@inline(__always)
public mutating func add(
int64 value: borrowing Int64,
key: borrowing String)
{
key: borrowing String
) {
add(key: key)
add(int64: value)
}
@@ -399,8 +398,8 @@ public struct FlexBuffersWriter {
@inline(__always)
public mutating func indirect(
int64 val: borrowing Int64,
key: borrowing String)
{
key: borrowing String
) {
add(key: key)
indirect(int64: val)
}
@@ -408,8 +407,8 @@ public struct FlexBuffersWriter {
@inline(__always)
public mutating func indirect(
int val: borrowing Int,
key: borrowing String)
{
key: borrowing String
) {
add(key: key)
indirect(int64: numericCast(val))
}
@@ -424,8 +423,8 @@ public struct FlexBuffersWriter {
@inline(__always)
public mutating func add(
float32 value: borrowing Float32,
key: borrowing String)
{
key: borrowing String
) {
add(key: key)
add(float32: value)
}
@@ -438,8 +437,8 @@ public struct FlexBuffersWriter {
@inline(__always)
public mutating func indirect(
float32 val: borrowing Float32,
key: borrowing String)
{
key: borrowing String
) {
add(key: key)
indirect(float32: val)
}
@@ -452,8 +451,8 @@ public struct FlexBuffersWriter {
@inline(__always)
public mutating func add(
double value: borrowing Double,
key: borrowing String)
{
key: borrowing String
) {
add(key: key)
add(double: value)
}
@@ -466,8 +465,8 @@ public struct FlexBuffersWriter {
@inline(__always)
public mutating func indirect(
double val: borrowing Double,
key: borrowing String)
{
key: borrowing String
) {
add(key: key)
indirect(double: val)
}
@@ -489,8 +488,8 @@ public struct FlexBuffersWriter {
@inline(__always)
public mutating func add<T>(
blob: borrowing T,
length l: Int) -> UInt where T: ContiguousBytes
{
length l: Int
) -> UInt where T: ContiguousBytes {
storeBlob(blob, len: l, type: .blob)
}
@@ -499,8 +498,8 @@ public struct FlexBuffersWriter {
public mutating func add<T>(
blob: borrowing T,
key: borrowing String,
length l: Int) -> UInt where T: ContiguousBytes
{
length l: Int
) -> UInt where T: ContiguousBytes {
add(key: key)
return storeBlob(blob, len: l, type: .blob)
}
@@ -541,8 +540,8 @@ public struct FlexBuffersWriter {
mutating func pushIndirect<T>(
value: T,
type: FlexBufferType,
bitWidth: BitWidth)
{
bitWidth: BitWidth
) {
let byteWidth = align(width: bitWidth)
let iloc = writerIndex
_bb.ensureSpace(size: byteWidth)
@@ -619,8 +618,8 @@ public struct FlexBuffersWriter {
mutating func storeBlob<T>(
_ bytes: T,
len: Int,
type: FlexBufferType) -> UInt where T: ContiguousBytes
{
type: FlexBufferType
) -> UInt where T: ContiguousBytes {
return bytes.withUnsafeBytes {
storeBlob(pointer: $0.baseAddress!, len: len, type: type)
}
@@ -632,8 +631,8 @@ public struct FlexBuffersWriter {
pointer: borrowing UnsafeRawPointer,
len: Int,
trailing: Int = 0,
type: FlexBufferType) -> UInt
{
type: FlexBufferType
) -> UInt {
_bb.ensureSpace(size: len &+ trailing)
let bitWidth = widthU(numericCast(len))
@@ -656,8 +655,7 @@ public struct FlexBuffersWriter {
@discardableResult
@usableFromInline
mutating func create<T>(vector: [T], fixed: Bool) -> Int
where T: Scalar
{
where T: Scalar {
let length: UInt64 = numericCast(vector.count)
let vectorType = getScalarType(type: T.self)
let byteWidth = MemoryLayout<T>.size
@@ -693,8 +691,8 @@ public struct FlexBuffersWriter {
step: Int,
typed: Bool,
fixed: Bool,
keys: Value? = nil) -> Value
{
keys: Value? = nil
) -> Value {
assert(
!fixed || typed,
"Typed false and fixed true is a combination not supported currently")
@@ -736,16 +734,17 @@ public struct FlexBuffersWriter {
let byteWidth = align(width: bitWidth)
let currentSize: Int = count &* step &* byteWidth
let requiredSize: Int = if !typed {
// We ensure that we have enough space
// for loop two write operations &
// 24 bytes for when its not fixed,
// and keys isn't null. As an extra safe
// guard
(currentSize &* 2) &+ twentyFourBytes
} else {
currentSize
}
let requiredSize: Int =
if !typed {
// We ensure that we have enough space
// for loop two write operations &
// 24 bytes for when its not fixed,
// and keys isn't null. As an extra safe
// guard
(currentSize &* 2) &+ twentyFourBytes
} else {
currentSize
}
_bb.ensureSpace(
size: requiredSize)
@@ -858,8 +857,8 @@ extension FlexBuffersWriter {
@discardableResult
public mutating func vector(
key: String,
_ closure: FlexBuffersWriterBuilder) -> UInt64
{
_ closure: FlexBuffersWriterBuilder
) -> UInt64 {
let start = startVector(key: key)
closure(&self)
return endVector(start: start)
@@ -880,8 +879,8 @@ extension FlexBuffersWriter {
@discardableResult
public mutating func map(
key: String,
_ closure: FlexBuffersWriterBuilder) -> UInt64
{
_ closure: FlexBuffersWriterBuilder
) -> UInt64 {
let start = startMap(key: key)
closure(&self)
return endMap(start: start)