[stdlib] Add an unsafe U[M]BP initializer to work around some inliner test failures

This commit is contained in:
Karoy Lorentey
2020-12-09 19:31:28 -08:00
parent 282a1408de
commit 1f92df093c
3 changed files with 12 additions and 4 deletions

View File

@@ -208,7 +208,7 @@ extension _SmallString {
// Restore the memory type of self._storage
_ = rawPtr.bindMemory(to: RawBitPattern.self, capacity: 1)
}
return try f(UnsafeBufferPointer(start: ptr, count: count))
return try f(UnsafeBufferPointer(_uncheckedStart: ptr, count: count))
}
}

View File

@@ -902,7 +902,7 @@ extension _StringObject {
return sharedUTF8
}
return UnsafeBufferPointer(
start: self.nativeUTF8Start, count: self.largeCount)
_uncheckedStart: self.nativeUTF8Start, count: self.largeCount)
}
// Whether the object stored can be bridged directly as a NSString

View File

@@ -394,6 +394,15 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
}
extension Unsafe${Mutable}BufferPointer {
@_alwaysEmitIntoClient
internal init(
@_nonEphemeral _uncheckedStart start: Unsafe${Mutable}Pointer<Element>?,
count: Int
) {
_position = start
self.count = count
}
/// Creates a new buffer pointer over the specified number of contiguous
/// instances beginning at the given pointer.
///
@@ -413,8 +422,7 @@ extension Unsafe${Mutable}BufferPointer {
_debugPrecondition(
count == 0 || start != nil,
"Unsafe${Mutable}BufferPointer has a nil start and nonzero count")
_position = start
self.count = _assumeNonNegative(count)
self.init(_uncheckedStart: start, count: _assumeNonNegative(count))
}
@inlinable // unsafe-performance