@@ -197,116 +197,67 @@ public struct ${Self}<Pointee>
197
197
}
198
198
199
199
/// Replace `count` initialized `Pointee`s starting at `self` with
200
- /// the `count` `Pointee`s at `source`, proceeding forward from
201
- /// `self` to `self + count - 1`.
200
+ /// the `count` `Pointee`s at `source`.
202
201
///
203
202
/// - Precondition: `count >= 0`
204
203
///
205
- /// - Precondition: `self` either precedes `source` or follows
206
- /// `source + count - 1`.
207
- ///
208
204
/// - Precondition: The `Pointee`s at `self..<self + count` and
209
205
/// `source..<source + count` are initialized.
210
- public func assignFrom( _ source: UnsafePointer < Pointee > , count: Int) {
211
- _debugPrecondition (
212
- count >= 0 , " ${Self}.assignFrom with negative count " )
206
+ public func assign( from source: UnsafePointer < Pointee > , count: Int) {
213
207
_debugPrecondition (
214
- UnsafePointer ( self ) < source || UnsafePointer ( self ) >= source + count,
215
- " assignFrom non-following overlapping range; use assignBackwardFrom " )
216
- for i in 0 ..< count {
217
- self [ i] = source [ i]
208
+ count >= 0 , " ${Self}.assign with negative count " )
209
+ if UnsafePointer ( self ) < source || UnsafePointer ( self ) >= source + count {
210
+ // assign forward from a disjoint or following overlapping range.
211
+ for i in 0 ..< count {
212
+ self [ i] = source [ i]
213
+ }
218
214
}
219
- }
220
-
221
- /// Replace `count` initialized `Pointee`s starting at `self` with
222
- /// the `count` `Pointee`s at `source`, proceeding backward from
223
- /// `self + count - 1` to `self`.
224
- ///
225
- /// Use `assignBackwardFrom` when copying elements into later memory
226
- /// that may overlap with the source range.
227
- ///
228
- /// - Precondition: `count >= 0`
229
- ///
230
- /// - Precondition: `source` either precedes `self` or follows
231
- /// `self + count - 1`.
232
- ///
233
- /// - Precondition: The `Pointee`s at `self..<self + count` and
234
- /// `source..<source + count` are initialized.
235
- public func assignBackwardFrom( _ source: UnsafePointer < Pointee > , count: Int) {
236
- _debugPrecondition (
237
- count >= 0 , " ${Self}.assignBackwardFrom with negative count " )
238
- _debugPrecondition (
239
- source < UnsafePointer ( self ) || source >= UnsafePointer ( self ) + count,
240
- " ${Self}.assignBackwardFrom non-preceding overlapping range; use assignFrom instead " )
241
- var i = count- 1
242
- while i >= 0 {
243
- self [ i] = source [ i]
244
- i -= 1
215
+ else {
216
+ // assign backward from a non-following overlapping range.
217
+ var i = count- 1
218
+ while i >= 0 {
219
+ self [ i] = source [ i]
220
+ i -= 1
221
+ }
245
222
}
246
223
}
247
224
248
225
/// Initialize memory starting at `self` with `count` `Pointee`s
249
- /// beginning at `source`, proceeding forward from `self` to `self +
250
- /// count - 1`, and returning the source memory to an uninitialized
251
- /// state.
252
- ///
253
- /// - Precondition: `count >= 0`
254
- ///
255
- /// - Precondition: `self` either precedes `source` or follows `source +
256
- /// count - 1`.
257
- ///
258
- /// - Precondition: The memory at `self..<self + count` is uninitialized
259
- /// and the `Pointees` at `source..<source + count` are
260
- /// initialized.
261
- ///
262
- /// - Postcondition: The `Pointee`s at `self..<self + count` are
263
- /// initialized and the memory at `source..<source + count` is
264
- /// uninitialized.
265
- public func moveInitializeFrom( _ source: ${ Self} , count: Int) {
266
- _debugPrecondition (
267
- count >= 0 , " ${Self}.moveInitializeFrom with negative count " )
268
- _debugPrecondition (
269
- self < source || self >= source + count,
270
- " ${Self}.moveInitializeFrom non-following overlapping range; use moveInitializeBackwardFrom " )
271
- Builtin . takeArrayFrontToBack (
272
- Pointee . self, self . _rawValue, source. _rawValue, count. _builtinWordValue)
273
- // This builtin is equivalent to:
274
- // for i in 0..<count {
275
- // (self + i).initialize(with: (source + i).move())
276
- // }
277
- }
278
-
279
- /// Initialize memory starting at `self` with `count` `Pointee`s
280
- /// beginning at `source`, proceeding backward from `self + count - 1`
281
- /// to `self`, and returning the source memory to an uninitialized
282
- /// state.
226
+ /// beginning at `source`, and returning the source memory to an
227
+ /// uninitialized state.
283
228
///
284
229
/// - Precondition: `count >= 0`
285
230
///
286
- /// - Precondition: `source` either precedes `self` or follows
287
- /// `self + count - 1`.
288
- ///
289
231
/// - Precondition: The memory at `self..<self + count` is uninitialized
290
232
/// and the `Pointees` at `source..<source + count` are
291
233
/// initialized.
292
234
///
293
235
/// - Postcondition: The `Pointee`s at `self..<self + count` are
294
236
/// initialized and the memory at `source..<source + count` is
295
237
/// uninitialized.
296
- public func moveInitializeBackwardFrom( _ source: ${ Self} , count: Int) {
297
- _debugPrecondition (
298
- count >= 0 , " ${Self}.moveInitializeBackwardFrom with negative count " )
238
+ public func moveInitialize( from source: ${ Self} , count: Int) {
299
239
_debugPrecondition (
300
- source < self || source >= self + count,
301
- " ${Self}.moveInitializeBackwardFrom non-preceding overlapping range; use moveInitializeFrom instead " )
302
- Builtin . takeArrayBackToFront (
303
- Pointee . self, self . _rawValue, source. _rawValue, count. _builtinWordValue)
304
- // This builtin is equivalent to:
305
- // var src = source + count
306
- // var dst = self + count
307
- // while dst != self {
308
- // (--dst).initialize(with: (--src).move())
309
- // }
240
+ count >= 0 , " ${Self}.moveInitialize with negative count " )
241
+ if self < source || self >= source + count {
242
+ // initialize forward from a disjoint or following overlapping range.
243
+ Builtin . takeArrayFrontToBack (
244
+ Pointee . self, self . _rawValue, source. _rawValue, count. _builtinWordValue)
245
+ // This builtin is equivalent to:
246
+ // for i in 0..<count {
247
+ // (self + i).initialize(with: (source + i).move())
248
+ // }
249
+ }
250
+ else {
251
+ // initialize backward from a non-following overlapping range.
252
+ Builtin . takeArrayBackToFront (
253
+ Pointee . self, self . _rawValue, source. _rawValue, count. _builtinWordValue)
254
+ // This builtin is equivalent to:
255
+ // var src = source + count
256
+ // var dst = self + count
257
+ // while dst != self {
258
+ // (--dst).initialize(with: (--src).move())
259
+ // }
260
+ }
310
261
}
311
262
312
263
/// Initialize memory starting at `self` with `count` `Pointee`s
@@ -315,22 +266,22 @@ public struct ${Self}<Pointee>
315
266
///
316
267
/// - Precondition: `count >= 0`
317
268
///
318
- /// - Precondition: `self` either precedes `source` or follows ` source +
319
- /// count - 1` .
269
+ /// - Precondition: The memory regions `source..< source + count`
270
+ /// and `self..<self + count` do not overlap .
320
271
///
321
272
/// - Precondition: The memory at `self..<self + count` is uninitialized
322
273
/// and the `Pointees` at `source..<source + count` are
323
274
/// initialized.
324
275
///
325
276
/// - Postcondition: The `Pointee`s at `self..<self + count` and
326
277
/// `source..<source + count` are initialized.
327
- public func initializeFrom ( _ source: UnsafePointer < Pointee > , count: Int) {
278
+ public func initialize ( from source: UnsafePointer < Pointee > , count: Int) {
328
279
_debugPrecondition (
329
- count >= 0 , " ${Self}.initializeFrom with negative count " )
280
+ count >= 0 , " ${Self}.initialize with negative count " )
330
281
_debugPrecondition (
331
282
UnsafePointer ( self ) + count <= source ||
332
283
source + count <= UnsafePointer ( self ) ,
333
- " ${Self}.initializeFrom non-following overlapping range " )
284
+ " ${Self}.initialize overlapping range " )
334
285
Builtin . copyArray (
335
286
Pointee . self, self . _rawValue, source. _rawValue, count. _builtinWordValue)
336
287
// This builtin is equivalent to:
@@ -346,7 +297,7 @@ public struct ${Self}<Pointee>
346
297
///
347
298
/// - Postcondition: The `Pointee`s at `self..<self + count` are
348
299
/// initialized.
349
- public func initializeFrom < C : Collection> ( _ source: C)
300
+ public func initialize < C : Collection> ( from source: C)
350
301
where C. Iterator. Element == Pointee {
351
302
source. _copyContents ( initializing: self )
352
303
}
@@ -357,20 +308,21 @@ public struct ${Self}<Pointee>
357
308
///
358
309
/// - Precondition: `count >= 0`
359
310
///
360
- /// - Precondition: The source and destination ranges do not overlap
311
+ /// - Precondition: The memory regions `source..<source + count`
312
+ /// and `self..<self + count` do not overlap.
361
313
///
362
314
/// - Precondition: The `Pointee`s at `self..<self + count` and
363
315
/// `source..<source + count` are initialized.
364
316
///
365
317
/// - Postcondition: The `Pointee`s at `self..<self + count` are
366
318
/// initialized and the `Pointees` at `source..<source + count`
367
319
/// are uninitialized.
368
- public func moveAssignFrom ( _ source: ${ Self} , count: Int) {
320
+ public func moveAssign ( from source: ${ Self} , count: Int) {
369
321
_debugPrecondition (
370
322
count >= 0 , " ${Self}.moveAssignFrom with negative count " )
371
323
_debugPrecondition (
372
324
self + count <= source || source + count <= self ,
373
- " moveAssignFrom overlapping range" )
325
+ " moveAssign overlapping range" )
374
326
Builtin . destroyArray ( Pointee . self, self . _rawValue, count. _builtinWordValue)
375
327
Builtin . takeArrayFrontToBack (
376
328
Pointee . self, self . _rawValue, source. _rawValue, count. _builtinWordValue)
@@ -573,6 +525,37 @@ extension ${Self} {
573
525
public func destroy( _ count: Int ) {
574
526
Builtin . unreachable ( )
575
527
}
528
+
529
+ @available ( * , unavailable, renamed: " initialize(from:count:) " )
530
+ public func initializeFrom( _ source: UnsafePointer < Pointee > , count: Int ) {
531
+ Builtin . unreachable ( )
532
+ }
533
+
534
+ @available ( * , unavailable, renamed: " assign(from:count:) " )
535
+ public func assignFrom( _ source: UnsafePointer < Pointee > , count: Int ) {
536
+ Builtin . unreachable ( )
537
+ }
538
+
539
+ @available ( * , unavailable, renamed: " assign(from:count:) " )
540
+ public func assignBackwardFrom( _ source: UnsafePointer < Pointee > , count: Int ) {
541
+ Builtin . unreachable ( )
542
+ }
543
+
544
+ @available ( * , unavailable, renamed: " moveInitialize(from:count:) " )
545
+ public func moveInitializeFrom( _ source: UnsafePointer < Pointee > , count: Int ) {
546
+ Builtin . unreachable ( )
547
+ }
548
+
549
+ @available ( * , unavailable, renamed: " moveInitialize(from:count:) " )
550
+ public func moveInitializeBackwardFrom( _ source: UnsafePointer < Pointee > ,
551
+ count: Int ) {
552
+ Builtin . unreachable ( )
553
+ }
554
+
555
+ @available ( * , unavailable, renamed: " moveAssign(from:count:) " )
556
+ public func moveAssignFrom( _ source: UnsafePointer < Pointee > , count: Int ) {
557
+ Builtin . unreachable ( )
558
+ }
576
559
% end
577
560
}
578
561
0 commit comments