A closure that receives an Unsafe
to the sequence’s contiguous storage.
withContiguousStorageIfAvailable(_:)
Availability 有効性
- iOS 15.0+
- iPadOS 15.0+
- macOS 12.0+
- Mac Catalyst 15.0+
- tvOS 15.0+
- watchOS 8.0+
- Xcode 13.0+
Technology
- Foundation ファウンデーション
Declaration 宣言
func withContiguousStorageIfAvailable<R>(_ body: (UnsafeBufferPointer
<(T.Value
?, U.Value
?, V.Value
?, W.Value
?, X.Value
?, Range
<AttributedString
.Index
>)>) throws -> R) rethrows -> R?
Parameters パラメータ
body
Buffer Pointer
Return Value 戻り値
The value returned from body
, unless the sequence doesn’t support contiguous storage, in which case the method ignores body
and returns nil
.
Discussion 議論
This method calls body(buffer)
, where buffer
is a pointer to the collection’s contiguous storage. If the contiguous storage doesn’t exist, the collection creates it. If the collection doesn’t support an internal representation in a form of contiguous storage, the method doesn’t call body
— it immediately returns nil
.
The optimizer can often eliminate bounds- and uniqueness-checking within an algorithm. When that fails, however, invoking the same algorithm on the buffer
argument may let you trade safety for speed.
Successive calls to this method may provide a different pointer on each call. Don’t store buffer
outside of this method.
A Collection
that provides its own implementation of this method must provide contiguous storage to its elements in the same order as they appear in the collection. This guarantees that it’s possible to generate contiguous mutable storage to any of its subsequences by slicing buffer
with a range formed from the distances to the subsequence’s start
and end
, respectively.
Note 注意
This documentation comment was inherited from Sequence
.
この文書化コメントは、Sequence
から引き継がれました。