This commit is contained in:
2026-08-17 01:21:55 +02:00
parent 5761d6e67a
commit 4bd1e24e75
265 changed files with 20617 additions and 24457 deletions
+11 -28
View File
@@ -27,32 +27,15 @@ public struct ByteBuffer {
@usableFromInline
final class Storage {
@usableFromInline
@frozen enum Blob: ~Copyable {
enum Blob {
#if !os(WASI)
case data(Data)
case bytes(any ContiguousBytes)
case bytes(ContiguousBytes)
#endif
case byteBuffer(_InternalByteBuffer)
case array([UInt8])
case pointer(UnsafeMutableRawPointer)
init(_ other: borrowing Blob) {
switch other {
#if !os(WASI)
case .data(let data):
self = .data(data)
case .bytes(let contiguousBytes):
self = .bytes(contiguousBytes)
#endif
case .byteBuffer(let internalByteBuffer):
self = .byteBuffer(internalByteBuffer)
case .array(let array):
self = .array(array)
case .pointer(let unsafeMutableRawPointer):
self = .pointer(unsafeMutableRawPointer)
}
}
}
/// This storage doesn't own the memory, therefore, we won't deallocate on deinit.
@@ -61,7 +44,7 @@ public struct ByteBuffer {
private let capacity: Int
/// Retained blob of data that requires the storage to retain a pointer to.
@usableFromInline
let retainedBlob: Blob
var retainedBlob: Blob
@usableFromInline
init(count: Int) {
@@ -74,9 +57,9 @@ public struct ByteBuffer {
}
@usableFromInline
init(blob: borrowing Blob, capacity count: Int) {
init(blob: Blob, capacity count: Int) {
capacity = count
retainedBlob = .init(blob)
retainedBlob = blob
isOwned = false
}
@@ -293,7 +276,7 @@ public struct ByteBuffer {
/// - removeBytes: Removes a number of bytes from the current size
@inline(__always)
init(
blob: borrowing Storage.Blob,
blob: Storage.Blob,
count: Int,
removing removeBytes: Int)
{
@@ -333,7 +316,7 @@ public struct ByteBuffer {
/// - def: Type of the object
/// - position: the index of the object in the buffer
@inline(__always)
public func read<T: BitwiseCopyable>(def: T.Type, position: Int) -> T {
public func read<T>(def: T.Type, position: Int) -> T {
_storage.readWithUnsafeRawPointer(position: position) {
$0.bindMemory(to: T.self, capacity: 1)
.pointee
@@ -377,10 +360,10 @@ public struct ByteBuffer {
@inline(__always)
func readSizedScalar<
T: BinaryInteger,
T1: BinaryInteger & BitwiseCopyable,
T2: BinaryInteger & BitwiseCopyable,
T3: BinaryInteger & BitwiseCopyable,
T4: BinaryInteger & BitwiseCopyable
T1: BinaryInteger,
T2: BinaryInteger,
T3: BinaryInteger,
T4: BinaryInteger
>(
def: T.Type,
t1: T1.Type,