Skip to content

Commit 98c50c3

Browse files
authored
Merge pull request #67003 from glessard/idiomatic-rebinding-7
Rebind Memory Idiomatically
2 parents c50263c + fd7ced1 commit 98c50c3

File tree

1 file changed

+1
-11
lines changed

1 file changed

+1
-11
lines changed

stdlib/public/core/SmallString.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -313,17 +313,7 @@ extension _SmallString {
313313
) rethrows {
314314
self.init()
315315
try self.withMutableCapacity {
316-
let capacity = $0.count
317-
let rawPtr = $0.baseAddress._unsafelyUnwrappedUnchecked
318-
// Rebind the underlying (UInt64, UInt64) tuple to UInt8 for the
319-
// duration of the closure. Accessing self after this rebind is undefined.
320-
let ptr = rawPtr.bindMemory(to: UInt8.self, capacity: capacity)
321-
defer {
322-
// Restore the memory type of self._storage
323-
_ = rawPtr.bindMemory(to: RawBitPattern.self, capacity: 1)
324-
}
325-
return try initializer(
326-
UnsafeMutableBufferPointer<UInt8>(start: ptr, count: capacity))
316+
try $0.withMemoryRebound(to: UInt8.self, initializer)
327317
}
328318
self._invariantCheck()
329319
}

0 commit comments

Comments
 (0)