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
/// `ByteBuffer` is the interface that stores the data for a `Flatbuffers` object
/// it allows users to Construct their buffers internally without much cost to performance
@usableFromInline
@@ -144,18 +144,18 @@ struct _InternalByteBuffer {
/// Adds a `ContiguousBytes` to buffer memory
/// - Parameter value: bytes to copy
#if swift(>=5.0) && !os(WASI)
@inline(__always)
@usableFromInline
mutating func push(bytes: ContiguousBytes) {
bytes.withUnsafeBytes { ptr in
ensureSpace(size: ptr.count)
memcpy(
_storage.memory.advanced(by: writerIndex &- ptr.count),
ptr.baseAddress!,
ptr.count)
_writerSize = _writerSize &+ ptr.count
@inline(__always)
@usableFromInline
mutating func push(bytes: ContiguousBytes) {
bytes.withUnsafeBytes { ptr in
ensureSpace(size: ptr.count)
memcpy(
_storage.memory.advanced(by: writerIndex &- ptr.count),
ptr.baseAddress!,
ptr.count)
_writerSize = _writerSize &+ ptr.count
}
}
}
#endif
/// Adds an object of type NativeStruct into the buffer
@@ -200,8 +200,7 @@ struct _InternalByteBuffer {
mutating func push(string str: String, len: Int) {
ensureSpace(size: len)
if str.utf8
.withContiguousStorageIfAvailable({ self.push(bytes: $0, len: len) }) !=
nil
.withContiguousStorageIfAvailable({ self.push(bytes: $0, len: len) }) != nil
{
} else {
let utf8View = str.utf8
@@ -219,8 +218,8 @@ struct _InternalByteBuffer {
@inline(__always)
mutating func push(
bytes: UnsafeBufferPointer<String.UTF8View.Element>,
len: Int) -> Bool
{
len: Int
) -> Bool {
memcpy(
_storage.memory.advanced(by: writerIndex &- len),
bytes.baseAddress!,
@@ -260,7 +259,7 @@ struct _InternalByteBuffer {
mutating func ensureSpace(size: Int) -> Int {
let expectedWriterIndex = size &+ _writerSize
if expectedWriterIndex > capacity {
let currentWritingIndex = capacity &- _writerSize
while capacity <= expectedWriterIndex {
capacity = capacity << 1
@@ -269,7 +268,6 @@ struct _InternalByteBuffer {
/// solution take from Apple-NIO
capacity = capacity.convertToPowerofTwo
_storage.reallocate(
capacity: capacity,
writerSize: _writerSize,
@@ -327,30 +325,32 @@ struct _InternalByteBuffer {
@inline(__always)
func withUnsafeBytes<T>(
_ body: (UnsafeRawBufferPointer) throws
-> T) rethrows -> T
{
try body(UnsafeRawBufferPointer(
start: _storage.memory,
count: capacity))
-> T
) rethrows -> T {
try body(
UnsafeRawBufferPointer(
start: _storage.memory,
count: capacity))
}
@discardableResult
@inline(__always)
func withUnsafeSlicedBytes<T>(
_ body: (UnsafeRawBufferPointer) throws
-> T) rethrows -> T
{
try body(UnsafeRawBufferPointer(
start: _storage.memory.advanced(by: writerIndex),
count: capacity &- writerIndex))
-> T
) rethrows -> T {
try body(
UnsafeRawBufferPointer(
start: _storage.memory.advanced(by: writerIndex),
count: capacity &- writerIndex))
}
@discardableResult
@inline(__always)
func withUnsafeRawPointer<T>(
_ body: (UnsafeMutableRawPointer) throws
-> T) rethrows -> T
{
-> T
) rethrows -> T {
try body(_storage.memory)
}
@@ -358,8 +358,8 @@ struct _InternalByteBuffer {
@inline(__always)
func readWithUnsafeRawPointer<T>(
position: Int,
_ body: (UnsafeRawPointer) throws -> T) rethrows -> T
{
_ body: (UnsafeRawPointer) throws -> T
) rethrows -> T {
try body(_storage.memory.advanced(by: position))
}
}