Skip to content

[DNM] SE pitch: Initialization improvements for UnsafePointer and UnsafeBufferPointer (draft) #39981

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
10 changes: 5 additions & 5 deletions stdlib/public/core/ArrayBufferProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ extension _ArrayBufferProtocol where Indices == Range<Int>{
// so as not to self-clobber.
newTailStart.moveInitialize(from: oldTailStart, count: tailCount)

// Assign over the original subrange
// Update the original subrange
var i = newValues.startIndex
for j in subrange {
elements[j] = newValues[i]
Expand Down Expand Up @@ -200,17 +200,17 @@ extension _ArrayBufferProtocol where Indices == Range<Int>{
let shrinkage = -growth
if tailCount > shrinkage { // If the tail length exceeds the shrinkage

// Assign over the rest of the replaced range with the first
// Update the rest of the replaced range with the first
// part of the tail.
newTailStart.moveAssign(from: oldTailStart, count: shrinkage)
newTailStart.moveUpdate(from: oldTailStart, count: shrinkage)

// Slide the rest of the tail back
oldTailStart.moveInitialize(
from: oldTailStart + shrinkage, count: tailCount - shrinkage)
}
else { // Tail fits within erased elements
// Assign over the start of the replaced range with the tail
newTailStart.moveAssign(from: oldTailStart, count: tailCount)
// Update the start of the replaced range with the tail
newTailStart.moveUpdate(from: oldTailStart, count: tailCount)

// Destroy elements remaining after the tail in subrange
(newTailStart + tailCount).deinitialize(
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Bitset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ extension _UnsafeBitset {
@inlinable
@inline(__always)
internal func clear() {
words.assign(repeating: .empty, count: wordCount)
words.update(repeating: .empty, count: wordCount)
}
}

Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/HashTable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ extension _HashTable {
@_effects(releasenone)
internal func copyContents(of other: _HashTable) {
_internalInvariant(bucketCount == other.bucketCount)
self.words.assign(from: other.words, count: wordCount)
self.words.update(from: other.words, count: wordCount)
}

/// Insert a new entry with the specified hash value into the table.
Expand Down Expand Up @@ -446,7 +446,7 @@ extension _HashTable {
// without a special case.
words[0] = Word.allBits.subtracting(elementsBelow: bucketCount)
} else {
words.assign(repeating: .empty, count: wordCount)
words.update(repeating: .empty, count: wordCount)
}
}

Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/StringGuts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func _persistCString(_ p: UnsafePointer<CChar>?) -> [CChar]? {
guard let s = p else { return nil }
let bytesToCopy = UTF8._nullCodeUnitOffset(in: s) + 1 // +1 for the terminating NUL
let result = [CChar](unsafeUninitializedCapacity: bytesToCopy) { buf, initedCount in
buf.baseAddress!.assign(from: s, count: bytesToCopy)
buf.baseAddress!.update(from: s, count: bytesToCopy)
initedCount = bytesToCopy
}
return result
Expand Down
Loading