mirror of
https://github.com/apple/swift-collections
synced 2026-11-30 05:18:44 +00:00
some more stuff
This commit is contained in:
3 files changed
+35
-26
No files matched your search
@@ -24,7 +24,7 @@ public struct Borrow<T: ~Copyable>: Copyable, ~Escapable {
|
||||
unsafe _pointer = UnsafePointer(Builtin.unprotectedAddressOfBorrow(value))
|
||||
}
|
||||
|
||||
@lifetime(copy owner)
|
||||
@lifetime(borrow owner)
|
||||
@_alwaysEmitIntoClient
|
||||
@_transparent
|
||||
public init<Owner: ~Copyable & ~Escapable>(
|
||||
|
||||
@@ -61,6 +61,20 @@ extension Box where T: ~Copyable {
|
||||
unsafe _pointer
|
||||
}
|
||||
}
|
||||
|
||||
@lifetime(borrow self)
|
||||
@_alwaysEmitIntoClient
|
||||
@_transparent
|
||||
public func borrow() -> Borrow<T> {
|
||||
unsafe Borrow(unsafeAddress: UnsafePointer(_pointer), owner: self)
|
||||
}
|
||||
|
||||
@lifetime(&self)
|
||||
@_alwaysEmitIntoClient
|
||||
@_transparent
|
||||
public mutating func mutate() -> Inout<T> {
|
||||
unsafe Inout(unsafeAddress: _pointer, owner: &self)
|
||||
}
|
||||
}
|
||||
|
||||
extension Box where T: Copyable {
|
||||
|
||||
@@ -15,33 +15,28 @@ extension Optional where Wrapped: ~Copyable {
|
||||
@lifetime(borrow self)
|
||||
@_addressableSelf
|
||||
public func borrow() -> Borrow<Wrapped>? {
|
||||
switch self {
|
||||
case .some:
|
||||
let pointer = unsafe UnsafePointer<Wrapped>(
|
||||
Builtin.unprotectedAddressOfBorrow(self)
|
||||
)
|
||||
|
||||
return unsafe Borrow(unsafeAddress: pointer, owner: self)
|
||||
|
||||
case .none:
|
||||
if self == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
let pointer = unsafe UnsafePointer<Wrapped>(
|
||||
Builtin.unprotectedAddressOfBorrow(self)
|
||||
)
|
||||
|
||||
return unsafe Borrow(unsafeAddress: pointer, owner: self)
|
||||
}
|
||||
|
||||
#if false // Compiler bug preventing this
|
||||
@lifetime(&self)
|
||||
public mutating func mutate() -> Inout<Wrapped>? {
|
||||
switch self {
|
||||
case .some:
|
||||
let pointer = unsafe UnsafeMutablePointer<Wrapped>(
|
||||
Builtin.unprotectedAddressOf(&self)
|
||||
)
|
||||
|
||||
return unsafe Inout(unsafeAddress: pointer, owner: &self)
|
||||
|
||||
case .none:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// #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)
|
||||
// }
|
||||
}
|
||||
Reference in new issue
Block a user