mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-25 12:28:39 +00:00
bulk code format fix (#8707)
This commit is contained in:
@@ -18,7 +18,10 @@ import Foundation
|
||||
|
||||
@usableFromInline
|
||||
enum BitWidth: UInt64, CaseIterable {
|
||||
case w8 = 0, w16 = 1, w32 = 2, w64 = 3
|
||||
case w8 = 0
|
||||
case w16 = 1
|
||||
case w32 = 2
|
||||
case w64 = 3
|
||||
}
|
||||
|
||||
extension BitWidth: Comparable {
|
||||
|
||||
@@ -14,11 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#if canImport(Common)
|
||||
import Common
|
||||
#endif
|
||||
import Foundation
|
||||
|
||||
#if canImport(Common)
|
||||
import Common
|
||||
#endif
|
||||
|
||||
extension UInt64 {
|
||||
static let one: UInt64 = 1
|
||||
}
|
||||
@@ -55,4 +56,3 @@ extension Optional {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#if canImport(Common)
|
||||
import Common
|
||||
#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
#if canImport(Common)
|
||||
import Common
|
||||
#endif
|
||||
|
||||
public struct Value: Equatable {
|
||||
|
||||
@usableFromInline
|
||||
@@ -110,9 +110,11 @@ extension Value {
|
||||
return bitWidth
|
||||
} else {
|
||||
for byteWidth in stride(from: 1, to: MemoryLayout<UInt64>.size, by: 2) {
|
||||
let _offsetLoc: UInt64 = numericCast(numericCast(size) &+ padding(
|
||||
bufSize: numericCast(size),
|
||||
elementSize: numericCast(byteWidth)))
|
||||
let _offsetLoc: UInt64 = numericCast(
|
||||
numericCast(size)
|
||||
&+ padding(
|
||||
bufSize: numericCast(size),
|
||||
elementSize: numericCast(byteWidth)))
|
||||
let offsetLoc = _offsetLoc &+ (index &* numericCast(byteWidth))
|
||||
let offset = offsetLoc &- u
|
||||
|
||||
|
||||
@@ -14,12 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#if canImport(Common)
|
||||
import Common
|
||||
#endif
|
||||
|
||||
import Foundation
|
||||
|
||||
#if canImport(Common)
|
||||
import Common
|
||||
#endif
|
||||
|
||||
@inline(__always)
|
||||
internal func isInline(_ t: FlexBufferType) -> Bool {
|
||||
return t <= .float || t == .bool
|
||||
@@ -73,17 +73,26 @@ func getScalarType<T>(type: T.Type) -> FlexBufferType where T: Scalar {
|
||||
|
||||
@inline(__always)
|
||||
func toTypedVector(type: FlexBufferType, length: UInt64) -> FlexBufferType {
|
||||
let type: UInt64 = switch length {
|
||||
case 0: type.rawValue &- FlexBufferType.int.rawValue &+ FlexBufferType
|
||||
.vectorInt.rawValue
|
||||
case 2: type.rawValue &- FlexBufferType.int.rawValue &+ FlexBufferType
|
||||
.vectorInt2.rawValue
|
||||
case 3: type.rawValue &- FlexBufferType.int.rawValue &+ FlexBufferType
|
||||
.vectorInt3.rawValue
|
||||
case 4: type.rawValue &- FlexBufferType.int.rawValue &+ FlexBufferType
|
||||
.vectorInt4.rawValue
|
||||
default: 0
|
||||
}
|
||||
let type: UInt64 =
|
||||
switch length {
|
||||
case 0:
|
||||
type.rawValue &- FlexBufferType.int.rawValue
|
||||
&+ FlexBufferType
|
||||
.vectorInt.rawValue
|
||||
case 2:
|
||||
type.rawValue &- FlexBufferType.int.rawValue
|
||||
&+ FlexBufferType
|
||||
.vectorInt2.rawValue
|
||||
case 3:
|
||||
type.rawValue &- FlexBufferType.int.rawValue
|
||||
&+ FlexBufferType
|
||||
.vectorInt3.rawValue
|
||||
case 4:
|
||||
type.rawValue &- FlexBufferType.int.rawValue
|
||||
&+ FlexBufferType
|
||||
.vectorInt4.rawValue
|
||||
default: 0
|
||||
}
|
||||
return FlexBufferType(rawValue: type) ?? .null
|
||||
}
|
||||
|
||||
@@ -100,7 +109,8 @@ func isTypedVectorType(type: FlexBufferType) -> Bool {
|
||||
@inline(__always)
|
||||
func toTypedVectorElementType(type: FlexBufferType) -> FlexBufferType? {
|
||||
return FlexBufferType(
|
||||
rawValue: type.rawValue &- FlexBufferType.vectorInt
|
||||
rawValue: type.rawValue
|
||||
&- FlexBufferType.vectorInt
|
||||
.rawValue &+ FlexBufferType.int.rawValue)
|
||||
}
|
||||
|
||||
@@ -115,12 +125,16 @@ func toFixedTypedVectorElementType(type: FlexBufferType)
|
||||
{
|
||||
assert(isFixedTypedVectorType(type: type))
|
||||
let fixedType: UInt64 = numericCast(
|
||||
type.rawValue &- FlexBufferType.vectorInt2
|
||||
type.rawValue
|
||||
&- FlexBufferType.vectorInt2
|
||||
.rawValue)
|
||||
let len: Int = numericCast(fixedType.dividedReportingOverflow(by: 3).partialValue &+ 2)
|
||||
return (
|
||||
FlexBufferType(rawValue: (fixedType.quotientAndRemainder(dividingBy: 3).remainder) &+ FlexBufferType.int.rawValue),
|
||||
len)
|
||||
FlexBufferType(
|
||||
rawValue: (fixedType.quotientAndRemainder(dividingBy: 3).remainder)
|
||||
&+ FlexBufferType.int.rawValue),
|
||||
len
|
||||
)
|
||||
}
|
||||
|
||||
// MARK: - Reader functions
|
||||
@@ -128,8 +142,8 @@ func toFixedTypedVectorElementType(type: FlexBufferType)
|
||||
@inline(__always)
|
||||
func binarySearch(
|
||||
vector: TypedVector,
|
||||
target: String) -> Int?
|
||||
{
|
||||
target: String
|
||||
) -> Int? {
|
||||
var left = 0
|
||||
var right = vector.count
|
||||
|
||||
@@ -149,14 +163,17 @@ func binarySearch(
|
||||
|
||||
@inline(__always)
|
||||
func readIndirect(buffer: ByteBuffer, offset: Int, _ byteWidth: UInt8) -> Int {
|
||||
return offset &- numericCast(buffer.readUInt64(
|
||||
offset: offset,
|
||||
byteWidth: byteWidth))
|
||||
return offset
|
||||
&- numericCast(
|
||||
buffer.readUInt64(
|
||||
offset: offset,
|
||||
byteWidth: byteWidth))
|
||||
}
|
||||
|
||||
@inline(__always)
|
||||
func getCount(buffer: ByteBuffer, offset: Int, byteWidth: UInt8) -> Int {
|
||||
Int(buffer.readUInt64(
|
||||
offset: offset &- numericCast(byteWidth),
|
||||
byteWidth: byteWidth))
|
||||
Int(
|
||||
buffer.readUInt64(
|
||||
offset: offset &- numericCast(byteWidth),
|
||||
byteWidth: byteWidth))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user