mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-01 19:58:15 +00:00
[Swift] Migrating benchmarks to a newer lib. (#8168)
* Adds Nativestructs pointer push into ByteBuffer Updates benchmarks & cleanup Adds native struct vector tests * Address PR comments * Add more benchmarks * Some benchmark cleanup * Return back to 1M structs * Tweak Structs benchmark * Moves swift Benchmarks folder from /tests to /benchmarks --------- Co-authored-by: Joakim Hassila <jocke@ordo.one>
This commit is contained in:
@@ -261,6 +261,20 @@ public struct ByteBuffer {
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds an array of type Scalar to the buffer memory
|
||||
/// - Parameter elements: An array of Scalars
|
||||
@inline(__always)
|
||||
@usableFromInline
|
||||
mutating func push<T: NativeStruct>(elements: [T]) {
|
||||
elements.withUnsafeBytes { ptr in
|
||||
ensureSpace(size: ptr.count)
|
||||
_storage.memory
|
||||
.advanced(by: writerIndex &- ptr.count)
|
||||
.copyMemory(from: ptr.baseAddress!, byteCount: ptr.count)
|
||||
self._writerSize = self._writerSize &+ ptr.count
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds a `ContiguousBytes` to buffer memory
|
||||
/// - Parameter value: bytes to copy
|
||||
#if swift(>=5.0) && !os(WASI)
|
||||
@@ -271,8 +285,8 @@ public struct ByteBuffer {
|
||||
ensureSpace(size: ptr.count)
|
||||
memcpy(
|
||||
_storage.memory.advanced(by: writerIndex &- ptr.count),
|
||||
UnsafeRawPointer(ptr.baseAddress!),
|
||||
ptr.count)
|
||||
UnsafeRawPointer(ptr.baseAddress!),
|
||||
ptr.count)
|
||||
self._writerSize = self._writerSize &+ ptr.count
|
||||
}
|
||||
}
|
||||
|
||||
@@ -623,9 +623,7 @@ public struct FlatBufferBuilder {
|
||||
startVector(
|
||||
structs.count * MemoryLayout<T>.size,
|
||||
elementSize: MemoryLayout<T>.alignment)
|
||||
for i in structs.reversed() {
|
||||
_ = create(struct: i)
|
||||
}
|
||||
_bb.push(elements: structs)
|
||||
return endVector(len: structs.count)
|
||||
}
|
||||
|
||||
|
||||
@@ -129,7 +129,9 @@ public enum Vector<U, S>: Verifiable where U: Verifiable, S: Verifiable {
|
||||
let range = try verifyRange(&verifier, at: position, of: UOffset.self)
|
||||
for index in stride(
|
||||
from: range.start,
|
||||
to: Int(clamping: range.start &+ (range.count &* MemoryLayout<Int32>.size)),
|
||||
to: Int(
|
||||
clamping: range
|
||||
.start &+ (range.count &* MemoryLayout<Int32>.size)),
|
||||
by: MemoryLayout<UOffset>.size)
|
||||
{
|
||||
try U.verify(&verifier, at: index, of: U.self)
|
||||
|
||||
Reference in New Issue
Block a user