@@ -90,7 +90,7 @@ public let DataBenchmarks = [
9090 legacyFactor: 20 ) ,
9191
9292 BenchmarkInfo ( name: " DataAppendArray " ,
93- runFunction: { append ( $0* 100 , arraySize : 809 , to: medium) } , tags: d,
93+ runFunction: { append ( $0* 100 , array : array809 , to: medium) } , tags: d,
9494 legacyFactor: 100 ) ,
9595
9696 BenchmarkInfo ( name: " DataReset " ,
@@ -203,6 +203,8 @@ let small = sampleData(.small)
203203let medium = sampleData ( . medium)
204204let large = sampleData ( . large)
205205
206+ let array809 = byteArray ( size: 809 )
207+
206208let repeatElementSeq = { count in
207209 return sequence ( state: count) { ( i: inout Int ) -> UInt8 ? in
208210 defer { i = i &- 1 } ; return i > 0 ? UInt8 ( 0xA0 ) : nil
@@ -217,10 +219,14 @@ enum SampleKind {
217219 case immutableBacking
218220}
219221
220- func fillBuffer( _ buffer: UnsafeMutableBufferPointer < UInt8 > ) {
221- for i in buffer. indices {
222- buffer [ i] = UInt8 ( truncatingIfNeeded: i)
222+ func byteArray( size: Int ) -> [ UInt8 ] {
223+ var bytes = [ UInt8] ( repeating: 0 , count: size)
224+ bytes. withUnsafeMutableBufferPointer { buffer in
225+ for i in buffer. indices {
226+ buffer [ i] = UInt8 ( truncatingIfNeeded: i)
227+ }
223228 }
229+ return bytes
224230}
225231
226232func sampleData( size: Int ) -> Data {
@@ -235,11 +241,7 @@ func sampleData(size: Int) -> Data {
235241
236242func sampleBridgedNSData( ) -> Data {
237243 let count = 1033
238- var bytes = [ UInt8] ( repeating: 0 , count: count)
239- bytes. withUnsafeMutableBufferPointer {
240- fillBuffer ( $0)
241- }
242- let data = NSData ( bytes: bytes, length: count)
244+ let data = NSData ( bytes: byteArray ( size: count) , length: count)
243245 return Data ( referencing: data)
244246}
245247
@@ -295,11 +297,7 @@ func append(_ N: Int, bytes count: Int, to data: Data) {
295297}
296298
297299@inline ( never)
298- func append( _ N: Int , arraySize: Int , to data: Data ) {
299- var bytes = [ UInt8] ( repeating: 0 , count: arraySize)
300- bytes. withUnsafeMutableBufferPointer {
301- fillBuffer ( $0)
302- }
300+ func append( _ N: Int , array bytes: [ UInt8 ] , to data: Data ) {
303301 for _ in 1 ... N {
304302 var copy = data
305303 copy. append ( contentsOf: bytes)
0 commit comments