add flatbuffers
commit 6da1cf79d90eb242e7da5318241d42279a3df3ba Author: Max Burke <max@urbanlogiq.com> Date: Sun Jan 19 14:47:28 2020 -0800 [rust] Add use declarations to Rust-generated bindings for imported FB definitions (#5645) * Bugfix for Rust generation of union fields named with language keywords
This commit is contained in:
31
flatbuffers/swift/Sources/FlatBuffers/Int+extension.swift
Normal file
31
flatbuffers/swift/Sources/FlatBuffers/Int+extension.swift
Normal file
@ -0,0 +1,31 @@
|
||||
import Foundation
|
||||
|
||||
extension Int {
|
||||
|
||||
/// Moves the current int into the nearest power of two
|
||||
///
|
||||
/// This is used since the UnsafeMutableRawPointer will face issues when writing/reading
|
||||
/// if the buffer alignment exceeds that actual size of the buffer
|
||||
var convertToPowerofTwo: Int {
|
||||
guard self > 0 else { return 1 }
|
||||
var n = UOffset(self)
|
||||
|
||||
#if arch(arm) || arch(i386)
|
||||
let max = UInt32(Int.max)
|
||||
#else
|
||||
let max = UInt32.max
|
||||
#endif
|
||||
|
||||
n -= 1
|
||||
n |= n >> 1
|
||||
n |= n >> 2
|
||||
n |= n >> 4
|
||||
n |= n >> 8
|
||||
n |= n >> 16
|
||||
if n != max {
|
||||
n += 1
|
||||
}
|
||||
|
||||
return Int(n)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user