Skip to content

Commit f2c126a

Browse files
committed
Add Sequence._withRawContiguousStorageIfAvailable
1 parent 19075e0 commit f2c126a

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

stdlib/public/core/Sequence.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ public protocol Sequence {
366366
func withContiguousStorageIfAvailable<R>(
367367
_ body: (UnsafeBufferPointer<Element>) throws -> R
368368
) rethrows -> R?
369+
370+
func _withRawContiguousStorageIfAvailable<R>(
371+
_ body: (UnsafeRawBufferPointer) throws -> R
372+
) rethrows -> R?
369373
}
370374

371375
// Provides a default associated type witness for Iterator when the
@@ -1111,6 +1115,15 @@ extension Sequence {
11111115
) rethrows -> R? {
11121116
return nil
11131117
}
1118+
1119+
@inlinable
1120+
public func _withRawContiguousStorageIfAvailable<R>(
1121+
_ body: (UnsafeRawBufferPointer) throws -> R
1122+
) rethrows -> R? {
1123+
return try withContiguousStorageIfAvailable {
1124+
try body(UnsafeRawBufferPointer($0))
1125+
}
1126+
}
11141127
}
11151128

11161129
// FIXME(ABI)#182

stdlib/public/core/UnsafeRawBufferPointer.swift.gyb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@ extension Unsafe${Mutable}RawBufferPointer: Sequence {
145145
public func makeIterator() -> Iterator {
146146
return Iterator(_position: _position, _end: _end)
147147
}
148+
149+
@inlinable @inline(__always)
150+
public func _withRawContiguousStorageIfAvailable<R>(
151+
_ body: (UnsafeRawBufferPointer) throws -> R
152+
) rethrows -> R? {
153+
% if not mutable:
154+
return try body(self)
155+
% else:
156+
return try body(UnsafeRawBufferPointer(self))
157+
% end
158+
}
148159
}
149160

150161
extension Unsafe${Mutable}RawBufferPointer: ${Mutable}Collection {

test/api-digester/Outputs/stability-stdlib-abi.swift.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,4 @@ Struct String has removed conformance to _HasContiguousBytes
9595
Struct Substring has removed conformance to _HasContiguousBytes
9696
Var String._providesContiguousBytesNoCopy has been removed
9797
Var Substring._providesContiguousBytesNoCopy has been removed
98+
Func Sequence._withRawContiguousStorageIfAvailable(_:) has been added as a protocol requirement

0 commit comments

Comments
 (0)