@@ -716,6 +716,14 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
716
716
}
717
717
}
718
718
719
+ @inlinable // This is @inlinable as tribially computable.
720
+ mutating func append( byte: UInt8 ) {
721
+ let count = self . count
722
+ assert ( count + 1 <= MemoryLayout< Buffer> . size)
723
+ Swift . withUnsafeMutableBytes ( of: & bytes) { $0 [ count] = byte }
724
+ self . length += 1
725
+ }
726
+
719
727
@inlinable // This is @inlinable as trivially computable.
720
728
mutating func append( contentsOf buffer: UnsafeRawBufferPointer ) {
721
729
guard buffer. count > 0 else { return }
@@ -2056,10 +2064,14 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
2056
2064
// Copy the contents of buffer...
2057
2065
_representation = _Representation ( UnsafeRawBufferPointer ( start: base, count: endIndex) )
2058
2066
2059
- // ... and append the rest byte-wise.
2067
+ // ... and append the rest byte-wise, buffering through an InlineData.
2068
+ var buffer = InlineData ( )
2060
2069
while let element = iter. next ( ) {
2061
- Swift . withUnsafeBytes ( of: element) {
2062
- _representation. append ( contentsOf: $0)
2070
+ if buffer. count < buffer. capacity {
2071
+ buffer. append ( byte: element)
2072
+ } else {
2073
+ buffer. withUnsafeBytes { _representation. append ( contentsOf: $0) }
2074
+ buffer. count = 0
2063
2075
}
2064
2076
}
2065
2077
}
@@ -2340,10 +2352,14 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
2340
2352
// Copy the contents of the buffer...
2341
2353
_representation. append ( contentsOf: UnsafeRawBufferPointer ( start: base, count: endIndex) )
2342
2354
2343
- /// ... and append the rest byte-wise.
2355
+ // ... and append the rest byte-wise, buffering through an InlineData.
2356
+ var buffer = InlineData ( )
2344
2357
while let element = iter. next ( ) {
2345
- Swift . withUnsafeBytes ( of: element) {
2346
- _representation. append ( contentsOf: $0)
2358
+ if buffer. count < buffer. capacity {
2359
+ buffer. append ( byte: element)
2360
+ } else {
2361
+ buffer. withUnsafeBytes { _representation. append ( contentsOf: $0) }
2362
+ buffer. count = 0
2347
2363
}
2348
2364
}
2349
2365
}
0 commit comments