Skip to content

Commit 0230efc

Browse files
authored
Rename UnsafePointer assign/initialize and eliminate Backward variants. (#3585)
Also fixes the comments to clarify that source and self memory must be disjoint.
1 parent 18fb99a commit 0230efc

File tree

13 files changed

+163
-203
lines changed

13 files changed

+163
-203
lines changed

benchmark/single-source/PopFront.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public func run_PopFrontUnsafePointer(_ N: Int) {
4545
var count = arrayCount
4646
while count != 0 {
4747
result += a[0]
48-
a.assignFrom(a + 1, count: count - 1)
48+
a.assign(from: a + 1, count: count - 1)
4949
count -= 1
5050
}
5151
CheckResults(result == arrayCount, "IncorrectResults in StringInterpolation: \(result) != \(arrayCount)")

stdlib/public/core/ArrayBufferProtocol.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ extension _ArrayBufferProtocol where Index == Int {
153153
if growth > 0 {
154154
// Slide the tail part of the buffer forwards, in reverse order
155155
// so as not to self-clobber.
156-
newTailStart.moveInitializeBackwardFrom(oldTailStart, count: tailCount)
156+
newTailStart.moveInitialize(from: oldTailStart, count: tailCount)
157157

158158
// Assign over the original subRange
159159
var i = newValues.startIndex
@@ -190,15 +190,15 @@ extension _ArrayBufferProtocol where Index == Int {
190190

191191
// Assign over the rest of the replaced range with the first
192192
// part of the tail.
193-
newTailStart.moveAssignFrom(oldTailStart, count: shrinkage)
193+
newTailStart.moveAssign(from: oldTailStart, count: shrinkage)
194194

195195
// Slide the rest of the tail back
196-
oldTailStart.moveInitializeFrom(
197-
oldTailStart + shrinkage, count: tailCount - shrinkage)
196+
oldTailStart.moveInitialize(
197+
from: oldTailStart + shrinkage, count: tailCount - shrinkage)
198198
}
199199
else { // Tail fits within erased elements
200200
// Assign over the start of the replaced range with the tail
201-
newTailStart.moveAssignFrom(oldTailStart, count: tailCount)
201+
newTailStart.moveAssign(from: oldTailStart, count: tailCount)
202202

203203
// Destroy elements remaining after the tail in subRange
204204
(newTailStart + tailCount).deinitialize(

stdlib/public/core/Arrays.swift.gyb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ extension ${Self} : RangeReplaceableCollection, _ArrayProtocol {
13331333
Swift.max(newCount, _growArrayCapacity(capacity))
13341334
: newCount)
13351335

1336-
(self._buffer.firstElementAddress + oldCount).initializeFrom(newElements)
1336+
(self._buffer.firstElementAddress + oldCount).initialize(from: newElements)
13371337
self._buffer.count = newCount
13381338
}
13391339

@@ -1888,15 +1888,15 @@ internal func _arrayOutOfPlaceUpdate<_Buffer, Initializer>(
18881888
backingStart.deinitialize(count: sourceOffset)
18891889

18901890
// Move the head items
1891-
destStart.moveInitializeFrom(sourceStart, count: headCount)
1891+
destStart.moveInitialize(from: sourceStart, count: headCount)
18921892

18931893
// Destroy unused source items
18941894
oldStart.deinitialize(count: oldCount)
18951895

18961896
initializeNewElements.call(newStart, count: newCount)
18971897

18981898
// Move the tail items
1899-
newEnd.moveInitializeFrom(oldStart + oldCount, count: tailCount)
1899+
newEnd.moveInitialize(from: oldStart + oldCount, count: tailCount)
19001900

19011901
// Destroy any items that may be lurking in a _SliceBuffer after
19021902
// its real last element

stdlib/public/core/Collection.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1676,7 +1676,7 @@ extension Sequence
16761676
) -> UnsafeMutablePointer<Iterator.Element> {
16771677
if let s = self._baseAddressIfContiguous {
16781678
let count = self.count
1679-
ptr.initializeFrom(s, count: count)
1679+
ptr.initialize(from: s, count: count)
16801680
_fixLifetime(self._owner)
16811681
return ptr + count
16821682
} else {

stdlib/public/core/ContiguousArrayBuffer.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,8 @@ struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
384384
_sanityCheck(bounds.upperBound <= count)
385385

386386
let initializedCount = bounds.upperBound - bounds.lowerBound
387-
target.initializeFrom(
388-
firstElementAddress + bounds.lowerBound,
389-
count: initializedCount)
387+
target.initialize(
388+
from: firstElementAddress + bounds.lowerBound, count: initializedCount)
390389
_fixLifetime(owner)
391390
return target + initializedCount
392391
}
@@ -507,18 +506,18 @@ public func += <Element, C : Collection>(
507506

508507
if _fastPath(newCount <= lhs.capacity) {
509508
lhs.count = newCount
510-
(lhs.firstElementAddress + oldCount).initializeFrom(rhs)
509+
(lhs.firstElementAddress + oldCount).initialize(from: rhs)
511510
}
512511
else {
513512
var newLHS = _ContiguousArrayBuffer<Element>(
514513
uninitializedCount: newCount,
515514
minimumCapacity: _growArrayCapacity(lhs.capacity))
516515

517-
newLHS.firstElementAddress.moveInitializeFrom(
518-
lhs.firstElementAddress, count: oldCount)
516+
newLHS.firstElementAddress.moveInitialize(
517+
from: lhs.firstElementAddress, count: oldCount)
519518
lhs.count = 0
520519
swap(&lhs, &newLHS)
521-
(lhs.firstElementAddress + oldCount).initializeFrom(rhs)
520+
(lhs.firstElementAddress + oldCount).initialize(from: rhs)
522521
}
523522
}
524523

@@ -653,9 +652,8 @@ internal struct _UnsafePartiallyInitializedContiguousArrayBuffer<Element> {
653652
uninitializedCount: newCapacity, minimumCapacity: 0)
654653
p = newResult.firstElementAddress + result.capacity
655654
remainingCapacity = newResult.capacity - result.capacity
656-
newResult.firstElementAddress.moveInitializeFrom(
657-
result.firstElementAddress,
658-
count: result.capacity)
655+
newResult.firstElementAddress.moveInitialize(
656+
from: result.firstElementAddress, count: result.capacity)
659657
result.count = 0
660658
swap(&result, &newResult)
661659
}

stdlib/public/core/SliceBuffer.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
190190
_sanityCheck(bounds.upperBound >= bounds.lowerBound)
191191
_sanityCheck(bounds.upperBound <= endIndex)
192192
let c = bounds.count
193-
target.initializeFrom(subscriptBaseAddress + bounds.lowerBound, count: c)
193+
target.initialize(from: subscriptBaseAddress + bounds.lowerBound, count: c)
194194
return target + c
195195
}
196196

@@ -338,8 +338,8 @@ extension _SliceBuffer {
338338
let result = _ContiguousArrayBuffer<Element>(
339339
uninitializedCount: count,
340340
minimumCapacity: 0)
341-
result.firstElementAddress.initializeFrom(
342-
firstElementAddress, count: count)
341+
result.firstElementAddress.initialize(
342+
from: firstElementAddress, count: count)
343343
return ContiguousArray(_buffer: result)
344344
}
345345
}

stdlib/public/core/StringCore.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,8 @@ extension _StringCore : RangeReplaceableCollection {
623623
let tailStart = rangeStart + (replacedCount << elementShift)
624624

625625
if growth > 0 {
626-
(tailStart + (growth << elementShift)).assignBackwardFrom(
627-
tailStart, count: tailCount << elementShift)
626+
(tailStart + (growth << elementShift)).assign(
627+
from: tailStart, count: tailCount << elementShift)
628628
}
629629

630630
if _fastPath(elementWidth == 1) {
@@ -643,8 +643,8 @@ extension _StringCore : RangeReplaceableCollection {
643643
}
644644

645645
if growth < 0 {
646-
(tailStart + (growth << elementShift)).assignFrom(
647-
tailStart, count: tailCount << elementShift)
646+
(tailStart + (growth << elementShift)).assign(
647+
from: tailStart, count: tailCount << elementShift)
648648
}
649649
}
650650
else {

stdlib/public/core/SwiftNativeNSArray.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ extension _SwiftNativeNSArrayWithContiguousStorage : _NSArrayCore {
8484

8585
// These objects are "returned" at +0, so treat them as values to
8686
// avoid retains.
87-
UnsafeMutablePointer<Int>(aBuffer).initializeFrom(
87+
UnsafeMutablePointer<Int>(aBuffer).initialize(from:
8888
UnsafeMutablePointer(objects.baseAddress! + range.location),
8989
count: range.length)
9090
}

0 commit comments

Comments
 (0)