@@ -1189,49 +1189,41 @@ class TestData : TestDataSuper {
1189
1189
1190
1190
// d should go from .empty representation to .inline.
1191
1191
// Appending a small enough sequence to fit in linline should actually be copied.
1192
- d. append ( contentsOf: repeatElement ( UInt8 ( 0x01 ) , count : 2 ) )
1193
- expectEqual ( Data ( [ 0x01 , 0x01 ] ) , d)
1192
+ d. append ( contentsOf: 0x00 ... 0x01 )
1193
+ expectEqual ( Data ( [ 0x00 , 0x01 ] ) , d)
1194
1194
1195
1195
// Appending another small sequence should similarly still work.
1196
- d. append ( contentsOf: repeatElement ( UInt8 ( 0x02 ) , count : 1 ) )
1197
- expectEqual ( Data ( [ 0x01 , 0x01 , 0x02 ] ) , d)
1196
+ d. append ( contentsOf: 0x02 ... 0x02 )
1197
+ expectEqual ( Data ( [ 0x00 , 0x01 , 0x02 ] ) , d)
1198
1198
1199
1199
// If we append a sequence of elements larger than a single InlineData, the internal append here should buffer.
1200
1200
// We want to make sure that buffering in this way does not accidentally drop trailing elements on the floor.
1201
- d. append ( contentsOf: repeatElement ( UInt8 ( 0x03 ) , count : 24 ) )
1202
- expectEqual ( Data ( [ 0x01 , 0x01 , 0x02 , 0x03 , 0x03 , 0x03 , 0x03 , 0x03 , 0x03 ,
1203
- 0x03 , 0x03 , 0x03 , 0x03 , 0x03 , 0x03 , 0x03 , 0x03 , 0x03 ,
1204
- 0x03 , 0x03 , 0x03 , 0x03 , 0x03 , 0x03 , 0x03 , 0x03 , 0x03 ] ) , d)
1201
+ d. append ( contentsOf: 0x03 ... 0x17 )
1202
+ expectEqual ( Data ( [ 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 ,
1203
+ 0x08 , 0x09 , 0x0A , 0x0B , 0x0C , 0x0D , 0x0E , 0x0F ,
1204
+ 0x10 , 0x11 , 0x12 , 0x13 , 0x14 , 0x15 , 0x16 , 0x17 ] ) , d)
1205
1205
}
1206
1206
1207
1207
// This test is like test_appendingNonContiguousSequence_exactCount but uses a sequence which reports 0 for its `.underestimatedCount`.
1208
1208
// This attempts to hit the worst-case scenario of `Data.append<S>(_:)` -- a discontiguous sequence of unknown length.
1209
1209
func test_appendingNonContiguousSequence_underestimatedCount( ) {
1210
- // underestimatedRepeatedElement does the same thing as repeatElement, but reports an `.underestimatedCount` of 0.
1211
- let underestimatedRepeatedElement = { ( element: UInt8 , count: Int ) in
1212
- return sequence ( state: count) { ( count: inout Int ) -> UInt8 ? in
1213
- defer { count -= 1 }
1214
- return count > 0 ? element : nil
1215
- }
1216
- }
1217
-
1218
1210
var d = Data ( )
1219
1211
1220
1212
// d should go from .empty representation to .inline.
1221
1213
// Appending a small enough sequence to fit in linline should actually be copied.
1222
- d. append ( contentsOf: underestimatedRepeatedElement ( UInt8 ( 0x01 ) , 2 ) )
1223
- expectEqual ( Data ( [ 0x01 , 0x01 ] ) , d)
1214
+ d. append ( contentsOf: ( 0x00 ... 0x01 ) . makeIterator ( ) ) // `.makeIterator()` produces a sequence whose `.underestimatedCount` is 0.
1215
+ expectEqual ( Data ( [ 0x00 , 0x01 ] ) , d)
1224
1216
1225
1217
// Appending another small sequence should similarly still work.
1226
- d. append ( contentsOf: underestimatedRepeatedElement ( UInt8 ( 0x02 ) , 1 ) )
1227
- expectEqual ( Data ( [ 0x01 , 0x01 , 0x02 ] ) , d)
1218
+ d. append ( contentsOf: ( 0x02 ... 0x02 ) . makeIterator ( ) ) // `.makeIterator()` produces a sequence whose `.underestimatedCount` is 0.
1219
+ expectEqual ( Data ( [ 0x00 , 0x01 , 0x02 ] ) , d)
1228
1220
1229
1221
// If we append a sequence of elements larger than a single InlineData, the internal append here should buffer.
1230
1222
// We want to make sure that buffering in this way does not accidentally drop trailing elements on the floor.
1231
- d. append ( contentsOf: underestimatedRepeatedElement ( UInt8 ( 0x03 ) , 24 ) )
1232
- expectEqual ( Data ( [ 0x01 , 0x01 , 0x02 , 0x03 , 0x03 , 0x03 , 0x03 , 0x03 , 0x03 ,
1233
- 0x03 , 0x03 , 0x03 , 0x03 , 0x03 , 0x03 , 0x03 , 0x03 , 0x03 ,
1234
- 0x03 , 0x03 , 0x03 , 0x03 , 0x03 , 0x03 , 0x03 , 0x03 , 0x03 ] ) , d)
1223
+ d. append ( contentsOf: ( 0x03 ... 0x17 ) . makeIterator ( ) ) // `.makeIterator()` produces a sequence whose `.underestimatedCount` is 0.
1224
+ expectEqual ( Data ( [ 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 ,
1225
+ 0x08 , 0x09 , 0x0A , 0x0B , 0x0C , 0x0D , 0x0E , 0x0F ,
1226
+ 0x10 , 0x11 , 0x12 , 0x13 , 0x14 , 0x15 , 0x16 , 0x17 ] ) , d)
1235
1227
}
1236
1228
1237
1229
func test_sequenceInitializers( ) {
0 commit comments