mirror of
https://github.com/apple/swift-collections
synced 2026-11-23 04:24:23 +00:00
- Container, MutableContainer: Replace iterator protocols with direct methods that return the next span following a particular index. This is a radical simplification, but it reintroduces some index validation during iteration, and may have undesirable overhead for complex container types. - RigidArray, DynamicArray, NewArray: Update to reflect changes - Span: Conform to RandomAccessContainer - Borrow, Inout: Normalize labels of “owner” parameters. Expose pointers within the package. - Shared: Normalize read() into borrow()
43 lines
1.2 KiB
Swift
43 lines
1.2 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift Collections open source project
|
|
//
|
|
// Copyright (c) 2025 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import Builtin
|
|
|
|
extension Optional where Wrapped: ~Copyable {
|
|
@lifetime(borrow self)
|
|
@_addressableSelf
|
|
public func borrow() -> Borrow<Wrapped>? {
|
|
if self == nil {
|
|
return nil
|
|
}
|
|
|
|
let pointer = unsafe UnsafePointer<Wrapped>(
|
|
Builtin.unprotectedAddressOfBorrow(self)
|
|
)
|
|
|
|
return unsafe Borrow(unsafeAddress: pointer, borrowing: self)
|
|
}
|
|
|
|
// #if false // Compiler bug preventing this
|
|
// @lifetime(&self)
|
|
// public mutating func mutate() -> Inout<Wrapped>? {
|
|
// if self == nil {
|
|
// return nil
|
|
// }
|
|
//
|
|
// let pointer = unsafe UnsafeMutablePointer<Wrapped>(
|
|
// Builtin.unprotectedAddressOf(&self)
|
|
// )
|
|
//
|
|
// return unsafe Inout(unsafeAddress: pointer, owner: &self)
|
|
// }
|
|
}
|