@@ -95,7 +95,10 @@ extension InlineArray where Element: ~Copyable {
9595 @_transparent
9696 internal var _mutableBuffer : UnsafeMutableBufferPointer < Element > {
9797 mutating get {
98- unsafe UnsafeMutableBufferPointer< Element > ( start: _mutableAddress, count: count)
98+ unsafe UnsafeMutableBufferPointer< Element > (
99+ start: _mutableAddress,
100+ count: count
101+ )
99102 }
100103 }
101104
@@ -121,14 +124,18 @@ extension InlineArray where Element: ~Copyable {
121124@available ( SwiftStdlib 6 . 2 , * )
122125extension InlineArray where Element: ~ Copyable {
123126 /// Initializes every element in this array, by calling the given closure
124- /// for each index.
127+ /// with each index.
125128 ///
126129 /// This will call the closure `count` times, where `count` is the static
127130 /// count of the array, to initialize every element by passing the closure
128- /// the index of the current element being initialized. The closure is allowed
129- /// to throw an error at any point during initialization at which point the
130- /// array will stop initialization, deinitialize every currently initialized
131- /// element, and throw the given error back out to the caller.
131+ /// the index of the current element being initialized.
132+ ///
133+ /// InlineArray<4, Int> { 1 << $0 } //-> [1, 2, 4, 8]
134+ ///
135+ /// The closure is allowed to throw an error at any point during
136+ /// initialization at which point the array will stop initialization,
137+ /// deinitialize every currently initialized element, and throw the given
138+ /// error back out to the caller.
132139 ///
133140 /// - Parameter body: A closure that returns an owned `Element` to emplace at
134141 /// the passed in index.
@@ -139,9 +146,7 @@ extension InlineArray where Element: ~Copyable {
139146 public init< E: Error > ( _ body: ( Index ) throws ( E ) -> Element ) throws ( E) {
140147#if $BuiltinEmplaceTypedThrows
141148 self = try Builtin . emplace { ( rawPtr) throws ( E) -> ( ) in
142- let buffer = InlineArray < count , Element > . _initializationBuffer (
143- start: rawPtr
144- )
149+ let buffer = Self . _initializationBuffer ( start: rawPtr)
145150
146151 for i in 0 ..< count {
147152 do throws ( E) {
@@ -164,19 +169,23 @@ extension InlineArray where Element: ~Copyable {
164169 }
165170
166171 /// Initializes every element in this array, by calling the given closure
167- /// for each previously initialized element.
172+ /// with each preceding element.
168173 ///
169174 /// This will call the closure `count - 1` times, where `count` is the static
170175 /// count of the array, to initialize every element by passing the closure an
171- /// immutable borrow reference to the previous element. The closure is allowed
172- /// to throw an error at any point during initialization at which point the
173- /// array will stop initialization, deinitialize every currently initialized
174- /// element, and throw the given error back out to the caller.
176+ /// immutable borrow reference to the preceding element.
177+ ///
178+ /// InlineArray<4, Int>(first: 1) { $0 << 1 } //-> [1, 2, 4, 8]
179+ ///
180+ /// The closure is allowed to throw an error at any point during
181+ /// initialization at which point the array will stop initialization,
182+ /// deinitialize every currently initialized element, and throw the given
183+ /// error back out to the caller.
175184 ///
176185 /// - Parameters:
177186 /// - first: The first value to emplace into the array.
178187 /// - next: A closure that takes an immutable borrow reference to the
179- /// previous element, and returns an owned `Element` instance to emplace
188+ /// preceding element, and returns an owned `Element` instance to emplace
180189 /// into the array.
181190 ///
182191 /// - Complexity: O(*n*), where *n* is the number of elements in the array.
@@ -194,11 +203,16 @@ extension InlineArray where Element: ~Copyable {
194203 var o : Element ? = first
195204
196205 self = try Builtin . emplace { ( rawPtr) throws ( E) -> ( ) in
197- let buffer = InlineArray < count , Element > . _initializationBuffer (
198- start: rawPtr
199- )
206+ let buffer = Self . _initializationBuffer ( start: rawPtr)
200207
201- unsafe buffer. initializeElement ( at: 0 , to: o. take ( ) . _consumingUncheckedUnwrapped ( ) )
208+ guard Self . count > 0 else {
209+ return
210+ }
211+
212+ unsafe buffer. initializeElement (
213+ at: 0 ,
214+ to: o. take ( ) . _consumingUncheckedUnwrapped ( )
215+ )
202216
203217 for i in 1 ..< count {
204218 do throws ( E) {
@@ -232,7 +246,7 @@ extension InlineArray where Element: Copyable {
232246 @_alwaysEmitIntoClient
233247 public init ( repeating value: Element ) {
234248 self = Builtin . emplace {
235- let buffer = InlineArray < count , Element > . _initializationBuffer ( start: $0)
249+ let buffer = Self . _initializationBuffer ( start: $0)
236250
237251 unsafe buffer. initialize ( repeating: value)
238252 }
@@ -431,8 +445,8 @@ extension InlineArray where Element: ~Copyable {
431445 return
432446 }
433447
434- _precondition ( indices . contains ( i ) , " Index out of bounds " )
435- _precondition ( indices . contains ( j ) , " Index out of bounds " )
448+ _checkIndex ( i )
449+ _checkIndex ( j )
436450
437451 let ithElement = unsafe _mutableBuffer . moveElement( from: i)
438452 let jthElement = unsafe _mutableBuffer . moveElement( from: j)
0 commit comments