Skip to content

Commit 30e167b

Browse files
committed
[stdlib] Add unchecked subscript to InlineArray
1 parent d0bab40 commit 30e167b

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

stdlib/public/core/InlineArray.swift

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,35 @@ extension InlineArray where Element: ~Copyable {
374374

375375
@_transparent
376376
unsafeMutableAddress {
377-
_checkIndex(i)
377+
_checkIndex(i)
378378
return unsafe _mutableAddress + i
379379
}
380380
}
381+
382+
/// Accesses the element at the specified position.
383+
///
384+
/// - Warning: This subscript trades safety for performance. Using an invalid
385+
/// index results in undefined behavior.
386+
///
387+
/// - Parameter i: The position of the element to access. `i` must be a valid
388+
/// index of the array that is not equal to the `endIndex` property.
389+
///
390+
/// - Complexity: O(1)
391+
@available(SwiftStdlib 6.2, *)
392+
@_addressableSelf
393+
@_alwaysEmitIntoClient
394+
@unsafe
395+
public subscript(unchecked i: Index) -> Element {
396+
@_transparent
397+
unsafeAddress {
398+
unsafe _address + i
399+
}
400+
401+
@_transparent
402+
unsafeMutableAddress {
403+
unsafe _mutableAddress + i
404+
}
405+
}
381406
}
382407

383408
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)