Skip to content

Commit 1f92df0

Browse files
committed
[stdlib] Add an unsafe U[M]BP initializer to work around some inliner test failures
1 parent 282a140 commit 1f92df0

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

stdlib/public/core/SmallString.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ extension _SmallString {
208208
// Restore the memory type of self._storage
209209
_ = rawPtr.bindMemory(to: RawBitPattern.self, capacity: 1)
210210
}
211-
return try f(UnsafeBufferPointer(start: ptr, count: count))
211+
return try f(UnsafeBufferPointer(_uncheckedStart: ptr, count: count))
212212
}
213213
}
214214

stdlib/public/core/StringObject.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ extension _StringObject {
902902
return sharedUTF8
903903
}
904904
return UnsafeBufferPointer(
905-
start: self.nativeUTF8Start, count: self.largeCount)
905+
_uncheckedStart: self.nativeUTF8Start, count: self.largeCount)
906906
}
907907

908908
// Whether the object stored can be bridged directly as a NSString

stdlib/public/core/UnsafeBufferPointer.swift.gyb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,15 @@ extension Unsafe${Mutable}BufferPointer: ${Mutable}Collection, RandomAccessColle
394394
}
395395

396396
extension Unsafe${Mutable}BufferPointer {
397+
@_alwaysEmitIntoClient
398+
internal init(
399+
@_nonEphemeral _uncheckedStart start: Unsafe${Mutable}Pointer<Element>?,
400+
count: Int
401+
) {
402+
_position = start
403+
self.count = count
404+
}
405+
397406
/// Creates a new buffer pointer over the specified number of contiguous
398407
/// instances beginning at the given pointer.
399408
///
@@ -413,8 +422,7 @@ extension Unsafe${Mutable}BufferPointer {
413422
_debugPrecondition(
414423
count == 0 || start != nil,
415424
"Unsafe${Mutable}BufferPointer has a nil start and nonzero count")
416-
_position = start
417-
self.count = _assumeNonNegative(count)
425+
self.init(_uncheckedStart: start, count: _assumeNonNegative(count))
418426
}
419427

420428
@inlinable // unsafe-performance

0 commit comments

Comments
 (0)