mirror of
https://github.com/apple/swift-collections
synced 2026-11-28 05:04:21 +00:00
Merge pull request #409 from lorentey/future-modernization
[Future] Adopt Swift 6; delete obsolete workarounds
This commit is contained in:
14 files changed
+65
-1771
No files matched your search
+30
-21
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version:5.10
|
||||
// swift-tools-version:6.0
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Swift Collections open source project
|
||||
@@ -52,12 +52,20 @@ var defines: [String] = [
|
||||
// "COLLECTIONS_SINGLE_MODULE",
|
||||
]
|
||||
|
||||
let _settings: [SwiftSetting] = defines.map { .define($0) } + [
|
||||
let _sharedSettings: [SwiftSetting] = defines.map { .define($0) } + [
|
||||
.enableExperimentalFeature("BuiltinModule"),
|
||||
.enableExperimentalFeature("NonescapableTypes"),
|
||||
.enableExperimentalFeature("BitwiseCopyable"),
|
||||
.enableExperimentalFeature("RawLayout")
|
||||
// .swiftLanguageVersion(.v5)
|
||||
.enableExperimentalFeature("RawLayout"),
|
||||
.enableExperimentalFeature("SuppressedAssociatedTypes"),
|
||||
]
|
||||
|
||||
let _settings: [SwiftSetting] = _sharedSettings + [
|
||||
.swiftLanguageVersion(.v6),
|
||||
]
|
||||
|
||||
let _testSettings: [SwiftSetting] = _sharedSettings + [
|
||||
.swiftLanguageVersion(.v5),
|
||||
]
|
||||
|
||||
struct CustomTarget {
|
||||
@@ -73,6 +81,7 @@ struct CustomTarget {
|
||||
var dependencies: [Target.Dependency]
|
||||
var directory: String
|
||||
var exclude: [String]
|
||||
var settings: [SwiftSetting]
|
||||
}
|
||||
|
||||
extension CustomTarget.Kind {
|
||||
@@ -97,14 +106,16 @@ extension CustomTarget {
|
||||
name: String,
|
||||
dependencies: [Target.Dependency] = [],
|
||||
directory: String? = nil,
|
||||
exclude: [String] = []
|
||||
exclude: [String] = [],
|
||||
settings: [SwiftSetting]? = nil
|
||||
) -> CustomTarget {
|
||||
CustomTarget(
|
||||
kind: kind,
|
||||
name: name,
|
||||
dependencies: dependencies,
|
||||
directory: directory ?? name,
|
||||
exclude: exclude)
|
||||
exclude: exclude,
|
||||
settings: settings ?? (kind.isTest ? _testSettings : _settings))
|
||||
}
|
||||
|
||||
func toTarget() -> Target {
|
||||
@@ -120,7 +131,7 @@ extension CustomTarget {
|
||||
dependencies: dependencies,
|
||||
path: kind.path(for: directory),
|
||||
exclude: exclude,
|
||||
swiftSettings: _settings,
|
||||
swiftSettings: settings,
|
||||
linkerSettings: linkerSettings)
|
||||
case .test:
|
||||
return Target.testTarget(
|
||||
@@ -128,7 +139,7 @@ extension CustomTarget {
|
||||
dependencies: dependencies,
|
||||
path: kind.path(for: directory),
|
||||
exclude: exclude,
|
||||
swiftSettings: _settings,
|
||||
swiftSettings: settings,
|
||||
linkerSettings: linkerSettings)
|
||||
}
|
||||
}
|
||||
@@ -175,7 +186,7 @@ extension Array where Element == CustomTarget {
|
||||
t.exclude.map { "\(t.name)/\($0)" }
|
||||
},
|
||||
sources: targets.map { "\($0.name)" },
|
||||
swiftSettings: _settings,
|
||||
swiftSettings: _testSettings,
|
||||
linkerSettings: linkerSettings)
|
||||
}
|
||||
}
|
||||
@@ -194,9 +205,6 @@ let targets: [CustomTarget] = [
|
||||
name: "_CollectionsUtilities",
|
||||
exclude: [
|
||||
"CMakeLists.txt",
|
||||
"Compatibility/UnsafeMutableBufferPointer+SE-0370.swift.gyb",
|
||||
"Compatibility/UnsafeMutablePointer+SE-0370.swift.gyb",
|
||||
"Compatibility/UnsafeRawPointer extensions.swift.gyb",
|
||||
"Debugging.swift.gyb",
|
||||
"Descriptions.swift.gyb",
|
||||
"IntegerTricks/FixedWidthInteger+roundUpToPowerOfTwo.swift.gyb",
|
||||
@@ -204,7 +212,6 @@ let targets: [CustomTarget] = [
|
||||
"IntegerTricks/UInt+first and last set bit.swift.gyb",
|
||||
"IntegerTricks/UInt+reversed.swift.gyb",
|
||||
"RandomAccessCollection+Offsets.swift.gyb",
|
||||
"Specialize.swift.gyb",
|
||||
"UnsafeBitSet/_UnsafeBitSet+Index.swift.gyb",
|
||||
"UnsafeBitSet/_UnsafeBitSet+_Word.swift.gyb",
|
||||
"UnsafeBitSet/_UnsafeBitSet.swift.gyb",
|
||||
@@ -213,14 +220,14 @@ let targets: [CustomTarget] = [
|
||||
]),
|
||||
|
||||
.target(
|
||||
kind: .exported,
|
||||
name: "Future",
|
||||
dependencies: ["_CollectionsUtilities"],
|
||||
exclude: ["CMakeLists.txt"]),
|
||||
kind: .exported,
|
||||
name: "Future",
|
||||
dependencies: ["_CollectionsUtilities"],
|
||||
exclude: ["CMakeLists.txt"]),
|
||||
.target(
|
||||
kind: .test,
|
||||
name: "FutureTests",
|
||||
dependencies: ["Future"]),
|
||||
kind: .test,
|
||||
name: "FutureTests",
|
||||
dependencies: ["Future", "_CollectionsTestSupport"]),
|
||||
|
||||
.target(
|
||||
kind: .exported,
|
||||
@@ -279,7 +286,9 @@ let targets: [CustomTarget] = [
|
||||
name: "_RopeModule",
|
||||
dependencies: ["_CollectionsUtilities"],
|
||||
directory: "RopeModule",
|
||||
exclude: ["CMakeLists.txt"]),
|
||||
exclude: ["CMakeLists.txt"],
|
||||
// FIXME: _modify accessors in RopeModule seem to be broken in Swift 6 mode
|
||||
settings: _sharedSettings + [.swiftLanguageVersion(.v5)]),
|
||||
.target(
|
||||
kind: .test,
|
||||
name: "RopeModuleTests",
|
||||
|
||||
@@ -41,9 +41,9 @@ extension _DequeBuffer: CustomStringConvertible {
|
||||
|
||||
/// The type-punned empty singleton storage instance.
|
||||
@usableFromInline
|
||||
internal let _emptyDequeStorage = _DequeBuffer<Void>.create(
|
||||
minimumCapacity: 0,
|
||||
makingHeaderWith: { _ in
|
||||
_DequeBufferHeader(capacity: 0, count: 0, startSlot: .init(at: 0))
|
||||
})
|
||||
|
||||
nonisolated(unsafe) internal let _emptyDequeStorage
|
||||
= _DequeBuffer<Void>.create(
|
||||
minimumCapacity: 0,
|
||||
makingHeaderWith: { _ in
|
||||
_DequeBufferHeader(capacity: 0, count: 0, startSlot: .init(at: 0))
|
||||
})
|
||||
@@ -26,6 +26,7 @@ internal typealias _RawHashStorage = ManagedBuffer<_HashNodeHeader, _RawHashNode
|
||||
/// `_HashNode.Storage` subclass is to allow storage instances to properly
|
||||
/// clean up after themselves in their `deinit` method.)
|
||||
@usableFromInline
|
||||
nonisolated(unsafe)
|
||||
internal let _emptySingleton: _RawHashStorage = _RawHashStorage.create(
|
||||
minimumCapacity: 0,
|
||||
makingHeaderWith: { _ in _HashNodeHeader(byteCapacity: 0) })
|
||||
|
||||
@@ -11,12 +11,8 @@ add_library(_CollectionsUtilities
|
||||
"autogenerated/Debugging.swift"
|
||||
"autogenerated/Descriptions.swift"
|
||||
"autogenerated/RandomAccessCollection+Offsets.swift"
|
||||
"autogenerated/Specialize.swift"
|
||||
"autogenerated/UnsafeBufferPointer+Extras.swift"
|
||||
"autogenerated/UnsafeMutableBufferPointer+Extras.swift"
|
||||
"Compatibility/autogenerated/UnsafeMutableBufferPointer+SE-0370.swift"
|
||||
"Compatibility/autogenerated/UnsafeMutablePointer+SE-0370.swift"
|
||||
"Compatibility/autogenerated/UnsafeRawPointer extensions.swift"
|
||||
"IntegerTricks/autogenerated/FixedWidthInteger+roundUpToPowerOfTwo.swift"
|
||||
"IntegerTricks/autogenerated/Integer rank.swift"
|
||||
"IntegerTricks/autogenerated/UInt+first and last set bit.swift"
|
||||
|
||||
-424
@@ -1,424 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Swift Collections open source project
|
||||
//
|
||||
// Copyright (c) 2022 - 2024 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Note: These are adapted from SE-0370 in the Swift 5.8 Standard Library.
|
||||
|
||||
%{
|
||||
from gyb_utils import *
|
||||
}%
|
||||
${autogenerated_warning()}
|
||||
|
||||
% for modifier in visibility_levels:
|
||||
${visibility_boilerplate(modifier)}
|
||||
#if swift(<5.8)
|
||||
extension UnsafeMutableBufferPointer {
|
||||
/// Deinitializes every instance in this buffer.
|
||||
///
|
||||
/// The region of memory underlying this buffer must be fully initialized.
|
||||
/// After calling `deinitialize(count:)`, the memory is uninitialized,
|
||||
/// but still bound to the `Element` type.
|
||||
///
|
||||
/// - Note: All buffer elements must already be initialized.
|
||||
///
|
||||
/// - Returns: A raw buffer to the same range of memory as this buffer.
|
||||
/// The range of memory is still bound to `Element`.
|
||||
@discardableResult
|
||||
@inlinable
|
||||
${modifier} func deinitialize() -> UnsafeMutableRawBufferPointer {
|
||||
guard let start = baseAddress else { return .init(start: nil, count: 0) }
|
||||
start.deinitialize(count: count)
|
||||
return .init(start: UnsafeMutableRawPointer(start),
|
||||
count: count * MemoryLayout<Element>.stride)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Note: this is left unconditionally enabled because we need the SR14663 workaround. :-(
|
||||
extension UnsafeMutableBufferPointer {
|
||||
/// Initializes the buffer's memory with
|
||||
/// every element of the source.
|
||||
///
|
||||
/// Prior to calling the `initialize(fromContentsOf:)` method on a buffer,
|
||||
/// the memory referenced by the buffer must be uninitialized,
|
||||
/// or the `Element` type must be a trivial type. After the call,
|
||||
/// the memory referenced by the buffer up to, but not including,
|
||||
/// the returned index is initialized.
|
||||
/// The buffer must reference enough memory to accommodate
|
||||
/// `source.count` elements.
|
||||
///
|
||||
/// The returned index is the position of the next uninitialized element
|
||||
/// in the buffer, one past the index of the last element written.
|
||||
/// If `source` contains no elements, the returned index is equal to the
|
||||
/// buffer's `startIndex`. If `source` contains as many elements as the buffer
|
||||
/// can hold, the returned index is equal to the buffer's `endIndex`.
|
||||
///
|
||||
/// - Precondition: `self.count` >= `source.count`
|
||||
///
|
||||
/// - Note: The memory regions referenced by `source` and this buffer
|
||||
/// must not overlap.
|
||||
///
|
||||
/// - Parameter source: A collection of elements to be used to
|
||||
/// initialize the buffer's storage.
|
||||
/// - Returns: The index one past the last element of the buffer initialized
|
||||
/// by this function.
|
||||
@inlinable
|
||||
${modifier} func initialize<C: Collection>(
|
||||
fromContentsOf source: C
|
||||
) -> Index
|
||||
where C.Element == Element {
|
||||
let count: Int? = source.withContiguousStorageIfAvailable {
|
||||
guard let sourceAddress = $0.baseAddress, !$0.isEmpty else {
|
||||
return 0
|
||||
}
|
||||
precondition(
|
||||
$0.count <= self.count,
|
||||
"buffer cannot contain every element from source."
|
||||
)
|
||||
baseAddress?.initialize(from: sourceAddress, count: $0.count)
|
||||
return $0.count
|
||||
}
|
||||
if let count = count {
|
||||
return startIndex.advanced(by: count)
|
||||
}
|
||||
|
||||
var (iterator, copied) = source._copyContents(initializing: self)
|
||||
precondition(
|
||||
iterator.next() == nil,
|
||||
"buffer cannot contain every element from source."
|
||||
)
|
||||
return startIndex.advanced(by: copied)
|
||||
}
|
||||
}
|
||||
|
||||
#if swift(<5.8)
|
||||
extension UnsafeMutableBufferPointer {
|
||||
/// Moves every element of an initialized source buffer into the
|
||||
/// uninitialized memory referenced by this buffer, leaving the source memory
|
||||
/// uninitialized and this buffer's memory initialized.
|
||||
///
|
||||
/// Prior to calling the `moveInitialize(fromContentsOf:)` method on a buffer,
|
||||
/// the memory it references must be uninitialized,
|
||||
/// or its `Element` type must be a trivial type. After the call,
|
||||
/// the memory referenced by the buffer up to, but not including,
|
||||
/// the returned index is initialized. The memory referenced by
|
||||
/// `source` is uninitialized after the function returns.
|
||||
/// The buffer must reference enough memory to accommodate
|
||||
/// `source.count` elements.
|
||||
///
|
||||
/// The returned index is the position of the next uninitialized element
|
||||
/// in the buffer, one past the index of the last element written.
|
||||
/// If `source` contains no elements, the returned index is equal to the
|
||||
/// buffer's `startIndex`. If `source` contains as many elements as the buffer
|
||||
/// can hold, the returned index is equal to the buffer's `endIndex`.
|
||||
///
|
||||
/// - Precondition: `self.count` >= `source.count`
|
||||
///
|
||||
/// - Note: The memory regions referenced by `source` and this buffer
|
||||
/// may overlap.
|
||||
///
|
||||
/// - Parameter source: A buffer containing the values to copy. The memory
|
||||
/// region underlying `source` must be initialized.
|
||||
/// - Returns: The index one past the last element of the buffer initialized
|
||||
/// by this function.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
${modifier} func moveInitialize(fromContentsOf source: Self) -> Index {
|
||||
guard let sourceAddress = source.baseAddress, !source.isEmpty else {
|
||||
return startIndex
|
||||
}
|
||||
precondition(
|
||||
source.count <= self.count,
|
||||
"buffer cannot contain every element from source."
|
||||
)
|
||||
baseAddress?.moveInitialize(from: sourceAddress, count: source.count)
|
||||
return startIndex.advanced(by: source.count)
|
||||
}
|
||||
|
||||
/// Moves every element of an initialized source buffer into the
|
||||
/// uninitialized memory referenced by this buffer, leaving the source memory
|
||||
/// uninitialized and this buffer's memory initialized.
|
||||
///
|
||||
/// Prior to calling the `moveInitialize(fromContentsOf:)` method on a buffer,
|
||||
/// the memory it references must be uninitialized,
|
||||
/// or its `Element` type must be a trivial type. After the call,
|
||||
/// the memory referenced by the buffer up to, but not including,
|
||||
/// the returned index is initialized. The memory referenced by
|
||||
/// `source` is uninitialized after the function returns.
|
||||
/// The buffer must reference enough memory to accommodate
|
||||
/// `source.count` elements.
|
||||
///
|
||||
/// The returned index is the position of the next uninitialized element
|
||||
/// in the buffer, one past the index of the last element written.
|
||||
/// If `source` contains no elements, the returned index is equal to the
|
||||
/// buffer's `startIndex`. If `source` contains as many elements as the buffer
|
||||
/// can hold, the returned index is equal to the buffer's `endIndex`.
|
||||
///
|
||||
/// - Precondition: `self.count` >= `source.count`
|
||||
///
|
||||
/// - Note: The memory regions referenced by `source` and this buffer
|
||||
/// may overlap.
|
||||
///
|
||||
/// - Parameter source: A buffer containing the values to copy. The memory
|
||||
/// region underlying `source` must be initialized.
|
||||
/// - Returns: The index one past the last element of the buffer initialized
|
||||
/// by this function.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
${modifier} func moveInitialize(fromContentsOf source: Slice<Self>) -> Index {
|
||||
return moveInitialize(fromContentsOf: Self(rebasing: source))
|
||||
}
|
||||
|
||||
/// Initializes the element at `index` to the given value.
|
||||
///
|
||||
/// The memory underlying the destination element must be uninitialized,
|
||||
/// or `Element` must be a trivial type. After a call to `initialize(to:)`,
|
||||
/// the memory underlying this element of the buffer is initialized.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - value: The value used to initialize the buffer element's memory.
|
||||
/// - index: The index of the element to initialize
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
${modifier} func initializeElement(at index: Index, to value: Element) {
|
||||
assert(startIndex <= index && index < endIndex)
|
||||
let p = baseAddress.unsafelyUnwrapped.advanced(by: index)
|
||||
p.initialize(to: value)
|
||||
}
|
||||
|
||||
/// Retrieves and returns the element at `index`,
|
||||
/// leaving that element's underlying memory uninitialized.
|
||||
///
|
||||
/// The memory underlying the element at `index` must be initialized.
|
||||
/// After calling `moveElement(from:)`, the memory underlying this element
|
||||
/// of the buffer is uninitialized, and still bound to type `Element`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - index: The index of the buffer element to retrieve and deinitialize.
|
||||
/// - Returns: The instance referenced by this index in this buffer.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
${modifier} func moveElement(from index: Index) -> Element {
|
||||
assert(startIndex <= index && index < endIndex)
|
||||
return baseAddress.unsafelyUnwrapped.advanced(by: index).move()
|
||||
}
|
||||
|
||||
/// Deinitializes the memory underlying the element at `index`.
|
||||
///
|
||||
/// The memory underlying the element at `index` must be initialized.
|
||||
/// After calling `deinitializeElement()`, the memory underlying this element
|
||||
/// of the buffer is uninitialized, and still bound to type `Element`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - index: The index of the buffer element to deinitialize.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
${modifier} func deinitializeElement(at index: Index) {
|
||||
assert(startIndex <= index && index < endIndex)
|
||||
let p = baseAddress.unsafelyUnwrapped.advanced(by: index)
|
||||
p.deinitialize(count: 1)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if swift(<5.8)
|
||||
extension Slice {
|
||||
/// Initializes the buffer slice's memory with with
|
||||
/// every element of the source.
|
||||
///
|
||||
/// Prior to calling the `initialize(fromContentsOf:)` method
|
||||
/// on a buffer slice, the memory it references must be uninitialized,
|
||||
/// or the `Element` type must be a trivial type. After the call,
|
||||
/// the memory referenced by the buffer slice up to, but not including,
|
||||
/// the returned index is initialized.
|
||||
/// The buffer slice must reference enough memory to accommodate
|
||||
/// `source.count` elements.
|
||||
///
|
||||
/// The returned index is the index of the next uninitialized element
|
||||
/// in the buffer slice, one past the index of the last element written.
|
||||
/// If `source` contains no elements, the returned index is equal to
|
||||
/// the buffer slice's `startIndex`. If `source` contains as many elements
|
||||
/// as the buffer slice can hold, the returned index is equal to
|
||||
/// to the slice's `endIndex`.
|
||||
///
|
||||
/// - Precondition: `self.count` >= `source.count`
|
||||
///
|
||||
/// - Note: The memory regions referenced by `source` and this buffer slice
|
||||
/// must not overlap.
|
||||
///
|
||||
/// - Parameter source: A collection of elements to be used to
|
||||
/// initialize the buffer slice's storage.
|
||||
/// - Returns: The index one past the last element of the buffer slice
|
||||
/// initialized by this function.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
${modifier} func initialize<C: Collection>(
|
||||
fromContentsOf source: C
|
||||
) -> Index where Base == UnsafeMutableBufferPointer<C.Element> {
|
||||
let buffer = Base(rebasing: self)
|
||||
let index = buffer.initialize(fromContentsOf: source)
|
||||
let distance = buffer.distance(from: buffer.startIndex, to: index)
|
||||
return startIndex.advanced(by: distance)
|
||||
}
|
||||
|
||||
/// Moves every element of an initialized source buffer into the
|
||||
/// uninitialized memory referenced by this buffer slice, leaving the
|
||||
/// source memory uninitialized and this buffer slice's memory initialized.
|
||||
///
|
||||
/// Prior to calling the `moveInitialize(fromContentsOf:)` method on a
|
||||
/// buffer slice, the memory it references must be uninitialized,
|
||||
/// or its `Element` type must be a trivial type. After the call,
|
||||
/// the memory referenced by the buffer slice up to, but not including,
|
||||
/// the returned index is initialized. The memory referenced by
|
||||
/// `source` is uninitialized after the function returns.
|
||||
/// The buffer slice must reference enough memory to accommodate
|
||||
/// `source.count` elements.
|
||||
///
|
||||
/// The returned index is the position of the next uninitialized element
|
||||
/// in the buffer slice, one past the index of the last element written.
|
||||
/// If `source` contains no elements, the returned index is equal to the
|
||||
/// slice's `startIndex`. If `source` contains as many elements as the slice
|
||||
/// can hold, the returned index is equal to the slice's `endIndex`.
|
||||
///
|
||||
/// - Note: The memory regions referenced by `source` and this buffer slice
|
||||
/// may overlap.
|
||||
///
|
||||
/// - Precondition: `self.count` >= `source.count`
|
||||
///
|
||||
/// - Parameter source: A buffer containing the values to copy.
|
||||
/// The memory region underlying `source` must be initialized.
|
||||
/// - Returns: The index one past the last element of the buffer slice
|
||||
/// initialized by this function.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
${modifier} func moveInitialize<Element>(
|
||||
fromContentsOf source: UnsafeMutableBufferPointer<Element>
|
||||
) -> Index where Base == UnsafeMutableBufferPointer<Element> {
|
||||
let buffer = Base(rebasing: self)
|
||||
let index = buffer.moveInitialize(fromContentsOf: source)
|
||||
let distance = buffer.distance(from: buffer.startIndex, to: index)
|
||||
return startIndex.advanced(by: distance)
|
||||
}
|
||||
|
||||
/// Moves every element of an initialized source buffer slice into the
|
||||
/// uninitialized memory referenced by this buffer slice, leaving the
|
||||
/// source memory uninitialized and this buffer slice's memory initialized.
|
||||
///
|
||||
/// Prior to calling the `moveInitialize(fromContentsOf:)` method on a
|
||||
/// buffer slice, the memory it references must be uninitialized,
|
||||
/// or its `Element` type must be a trivial type. After the call,
|
||||
/// the memory referenced by the buffer slice up to, but not including,
|
||||
/// the returned index is initialized. The memory referenced by
|
||||
/// `source` is uninitialized after the function returns.
|
||||
/// The buffer slice must reference enough memory to accommodate
|
||||
/// `source.count` elements.
|
||||
///
|
||||
/// The returned index is the position of the next uninitialized element
|
||||
/// in the buffer slice, one past the index of the last element written.
|
||||
/// If `source` contains no elements, the returned index is equal to the
|
||||
/// slice's `startIndex`. If `source` contains as many elements as the slice
|
||||
/// can hold, the returned index is equal to the slice's `endIndex`.
|
||||
///
|
||||
/// - Note: The memory regions referenced by `source` and this buffer slice
|
||||
/// may overlap.
|
||||
///
|
||||
/// - Precondition: `self.count` >= `source.count`
|
||||
///
|
||||
/// - Parameter source: A buffer slice containing the values to copy.
|
||||
/// The memory region underlying `source` must be initialized.
|
||||
/// - Returns: The index one past the last element of the buffer slice
|
||||
/// initialized by this function.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
${modifier} func moveInitialize<Element>(
|
||||
fromContentsOf source: Slice<UnsafeMutableBufferPointer<Element>>
|
||||
) -> Index where Base == UnsafeMutableBufferPointer<Element> {
|
||||
let buffer = Base(rebasing: self)
|
||||
let index = buffer.moveInitialize(fromContentsOf: source)
|
||||
let distance = buffer.distance(from: buffer.startIndex, to: index)
|
||||
return startIndex.advanced(by: distance)
|
||||
}
|
||||
|
||||
/// Deinitializes every instance in this buffer slice.
|
||||
///
|
||||
/// The region of memory underlying this buffer slice must be fully
|
||||
/// initialized. After calling `deinitialize(count:)`, the memory
|
||||
/// is uninitialized, but still bound to the `Element` type.
|
||||
///
|
||||
/// - Note: All buffer elements must already be initialized.
|
||||
///
|
||||
/// - Returns: A raw buffer to the same range of memory as this buffer.
|
||||
/// The range of memory is still bound to `Element`.
|
||||
@discardableResult
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
${modifier} func deinitialize<Element>() -> UnsafeMutableRawBufferPointer
|
||||
where Base == UnsafeMutableBufferPointer<Element> {
|
||||
Base(rebasing: self).deinitialize()
|
||||
}
|
||||
|
||||
/// Initializes the element at `index` to the given value.
|
||||
///
|
||||
/// The memory underlying the destination element must be uninitialized,
|
||||
/// or `Element` must be a trivial type. After a call to `initialize(to:)`,
|
||||
/// the memory underlying this element of the buffer slice is initialized.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - value: The value used to initialize the buffer element's memory.
|
||||
/// - index: The index of the element to initialize
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
${modifier} func initializeElement<Element>(at index: Int, to value: Element)
|
||||
where Base == UnsafeMutableBufferPointer<Element> {
|
||||
assert(startIndex <= index && index < endIndex)
|
||||
base.baseAddress.unsafelyUnwrapped.advanced(by: index).initialize(to: value)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if swift(<5.8)
|
||||
extension UnsafeMutableBufferPointer {
|
||||
/// Updates every element of this buffer's initialized memory.
|
||||
///
|
||||
/// The buffer’s memory must be initialized or its `Element` type
|
||||
/// must be a trivial type.
|
||||
///
|
||||
/// - Note: All buffer elements must already be initialized.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - repeatedValue: The value used when updating this pointer's memory.
|
||||
@_alwaysEmitIntoClient
|
||||
${modifier} func update(repeating repeatedValue: Element) {
|
||||
guard let dstBase = baseAddress else { return }
|
||||
dstBase.update(repeating: repeatedValue, count: count)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if swift(<5.8)
|
||||
extension Slice {
|
||||
/// Updates every element of this buffer slice's initialized memory.
|
||||
///
|
||||
/// The buffer slice’s memory must be initialized or its `Element`
|
||||
/// must be a trivial type.
|
||||
///
|
||||
/// - Note: All buffer elements must already be initialized.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - repeatedValue: The value used when updating this pointer's memory.
|
||||
@_alwaysEmitIntoClient
|
||||
${modifier} func update<Element>(repeating repeatedValue: Element)
|
||||
where Base == UnsafeMutableBufferPointer<Element> {
|
||||
Base(rebasing: self).update(repeating: repeatedValue)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
% end
|
||||
${visibility_boilerplate("end")}
|
||||
@@ -1,43 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Swift Collections open source project
|
||||
//
|
||||
// Copyright (c) 2022 - 2024 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
%{
|
||||
from gyb_utils import *
|
||||
}%
|
||||
${autogenerated_warning()}
|
||||
|
||||
% for modifier in visibility_levels:
|
||||
${visibility_boilerplate(modifier)}
|
||||
#if swift(<5.8)
|
||||
extension UnsafeMutablePointer {
|
||||
/// Update this pointer's initialized memory with the specified number of
|
||||
/// consecutive copies of the given value.
|
||||
///
|
||||
/// The region of memory starting at this pointer and covering `count`
|
||||
/// instances of the pointer's `Pointee` type must be initialized or
|
||||
/// `Pointee` must be a trivial type. After calling
|
||||
/// `update(repeating:count:)`, the region is initialized.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - repeatedValue: The value used when updating this pointer's memory.
|
||||
/// - count: The number of consecutive elements to update.
|
||||
/// `count` must not be negative.
|
||||
@_alwaysEmitIntoClient
|
||||
${modifier} func update(repeating repeatedValue: Pointee, count: Int) {
|
||||
assert(count >= 0, "UnsafeMutablePointer.update(repeating:count:) with negative count")
|
||||
for i in 0 ..< count {
|
||||
self[i] = repeatedValue
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
% end
|
||||
${visibility_boilerplate("end")}
|
||||
@@ -1,89 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Swift Collections open source project
|
||||
//
|
||||
// Copyright (c) 2022 - 2024 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
%{
|
||||
from gyb_utils import *
|
||||
}%
|
||||
${autogenerated_warning()}
|
||||
|
||||
% for modifier in visibility_levels:
|
||||
${visibility_boilerplate(modifier)}
|
||||
#if compiler(<5.7) || (os(macOS) && compiler(<5.8)) // SE-0334
|
||||
extension UnsafeRawPointer {
|
||||
/// Obtain the next pointer properly aligned to store a value of type `T`.
|
||||
///
|
||||
/// If `self` is properly aligned for accessing `T`,
|
||||
/// this function returns `self`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - type: the type to be stored at the returned address.
|
||||
/// - Returns: a pointer properly aligned to store a value of type `T`.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
${modifier} func alignedUp<T>(for type: T.Type) -> Self {
|
||||
let mask = UInt(MemoryLayout<T>.alignment) &- 1
|
||||
let bits = (UInt(bitPattern: self) &+ mask) & ~mask
|
||||
return Self(bitPattern: bits)!
|
||||
}
|
||||
|
||||
/// Obtain the preceding pointer properly aligned to store a value of type `T`.
|
||||
///
|
||||
/// If `self` is properly aligned for accessing `T`,
|
||||
/// this function returns `self`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - type: the type to be stored at the returned address.
|
||||
/// - Returns: a pointer properly aligned to store a value of type `T`.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
${modifier} func alignedDown<T>(for type: T.Type) -> Self {
|
||||
let mask = UInt(MemoryLayout<T>.alignment) &- 1
|
||||
let bits = UInt(bitPattern: self) & ~mask
|
||||
return Self(bitPattern: bits)!
|
||||
}
|
||||
}
|
||||
|
||||
extension UnsafeMutableRawPointer {
|
||||
/// Obtain the next pointer properly aligned to store a value of type `T`.
|
||||
///
|
||||
/// If `self` is properly aligned for accessing `T`,
|
||||
/// this function returns `self`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - type: the type to be stored at the returned address.
|
||||
/// - Returns: a pointer properly aligned to store a value of type `T`.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
${modifier} func alignedUp<T>(for type: T.Type) -> Self {
|
||||
let mask = UInt(MemoryLayout<T>.alignment) &- 1
|
||||
let bits = (UInt(bitPattern: self) &+ mask) & ~mask
|
||||
return Self(bitPattern: bits)!
|
||||
}
|
||||
|
||||
/// Obtain the preceding pointer properly aligned to store a value of type `T`.
|
||||
///
|
||||
/// If `self` is properly aligned for accessing `T`,
|
||||
/// this function returns `self`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - type: the type to be stored at the returned address.
|
||||
/// - Returns: a pointer properly aligned to store a value of type `T`.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
${modifier} func alignedDown<T>(for type: T.Type) -> Self {
|
||||
let mask = UInt(MemoryLayout<T>.alignment) &- 1
|
||||
let bits = UInt(bitPattern: self) & ~mask
|
||||
return Self(bitPattern: bits)!
|
||||
}
|
||||
}
|
||||
#endif
|
||||
% end
|
||||
${visibility_boilerplate("end")}
|
||||
-832
@@ -1,832 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Swift Collections open source project
|
||||
//
|
||||
// Copyright (c) 2022 - 2024 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Note: These are adapted from SE-0370 in the Swift 5.8 Standard Library.
|
||||
|
||||
|
||||
// #############################################################################
|
||||
// # #
|
||||
// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. #
|
||||
// # #
|
||||
// #############################################################################
|
||||
|
||||
|
||||
|
||||
// In single module mode, we need these declarations to be internal,
|
||||
// but in regular builds we want them to be public. Unfortunately
|
||||
// the current best way to do this is to duplicate all definitions.
|
||||
#if COLLECTIONS_SINGLE_MODULE
|
||||
#if swift(<5.8)
|
||||
extension UnsafeMutableBufferPointer {
|
||||
/// Deinitializes every instance in this buffer.
|
||||
///
|
||||
/// The region of memory underlying this buffer must be fully initialized.
|
||||
/// After calling `deinitialize(count:)`, the memory is uninitialized,
|
||||
/// but still bound to the `Element` type.
|
||||
///
|
||||
/// - Note: All buffer elements must already be initialized.
|
||||
///
|
||||
/// - Returns: A raw buffer to the same range of memory as this buffer.
|
||||
/// The range of memory is still bound to `Element`.
|
||||
@discardableResult
|
||||
@inlinable
|
||||
internal func deinitialize() -> UnsafeMutableRawBufferPointer {
|
||||
guard let start = baseAddress else { return .init(start: nil, count: 0) }
|
||||
start.deinitialize(count: count)
|
||||
return .init(start: UnsafeMutableRawPointer(start),
|
||||
count: count * MemoryLayout<Element>.stride)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Note: this is left unconditionally enabled because we need the SR14663 workaround. :-(
|
||||
extension UnsafeMutableBufferPointer {
|
||||
/// Initializes the buffer's memory with
|
||||
/// every element of the source.
|
||||
///
|
||||
/// Prior to calling the `initialize(fromContentsOf:)` method on a buffer,
|
||||
/// the memory referenced by the buffer must be uninitialized,
|
||||
/// or the `Element` type must be a trivial type. After the call,
|
||||
/// the memory referenced by the buffer up to, but not including,
|
||||
/// the returned index is initialized.
|
||||
/// The buffer must reference enough memory to accommodate
|
||||
/// `source.count` elements.
|
||||
///
|
||||
/// The returned index is the position of the next uninitialized element
|
||||
/// in the buffer, one past the index of the last element written.
|
||||
/// If `source` contains no elements, the returned index is equal to the
|
||||
/// buffer's `startIndex`. If `source` contains as many elements as the buffer
|
||||
/// can hold, the returned index is equal to the buffer's `endIndex`.
|
||||
///
|
||||
/// - Precondition: `self.count` >= `source.count`
|
||||
///
|
||||
/// - Note: The memory regions referenced by `source` and this buffer
|
||||
/// must not overlap.
|
||||
///
|
||||
/// - Parameter source: A collection of elements to be used to
|
||||
/// initialize the buffer's storage.
|
||||
/// - Returns: The index one past the last element of the buffer initialized
|
||||
/// by this function.
|
||||
@inlinable
|
||||
internal func initialize<C: Collection>(
|
||||
fromContentsOf source: C
|
||||
) -> Index
|
||||
where C.Element == Element {
|
||||
let count: Int? = source.withContiguousStorageIfAvailable {
|
||||
guard let sourceAddress = $0.baseAddress, !$0.isEmpty else {
|
||||
return 0
|
||||
}
|
||||
precondition(
|
||||
$0.count <= self.count,
|
||||
"buffer cannot contain every element from source."
|
||||
)
|
||||
baseAddress?.initialize(from: sourceAddress, count: $0.count)
|
||||
return $0.count
|
||||
}
|
||||
if let count = count {
|
||||
return startIndex.advanced(by: count)
|
||||
}
|
||||
|
||||
var (iterator, copied) = source._copyContents(initializing: self)
|
||||
precondition(
|
||||
iterator.next() == nil,
|
||||
"buffer cannot contain every element from source."
|
||||
)
|
||||
return startIndex.advanced(by: copied)
|
||||
}
|
||||
}
|
||||
|
||||
#if swift(<5.8)
|
||||
extension UnsafeMutableBufferPointer {
|
||||
/// Moves every element of an initialized source buffer into the
|
||||
/// uninitialized memory referenced by this buffer, leaving the source memory
|
||||
/// uninitialized and this buffer's memory initialized.
|
||||
///
|
||||
/// Prior to calling the `moveInitialize(fromContentsOf:)` method on a buffer,
|
||||
/// the memory it references must be uninitialized,
|
||||
/// or its `Element` type must be a trivial type. After the call,
|
||||
/// the memory referenced by the buffer up to, but not including,
|
||||
/// the returned index is initialized. The memory referenced by
|
||||
/// `source` is uninitialized after the function returns.
|
||||
/// The buffer must reference enough memory to accommodate
|
||||
/// `source.count` elements.
|
||||
///
|
||||
/// The returned index is the position of the next uninitialized element
|
||||
/// in the buffer, one past the index of the last element written.
|
||||
/// If `source` contains no elements, the returned index is equal to the
|
||||
/// buffer's `startIndex`. If `source` contains as many elements as the buffer
|
||||
/// can hold, the returned index is equal to the buffer's `endIndex`.
|
||||
///
|
||||
/// - Precondition: `self.count` >= `source.count`
|
||||
///
|
||||
/// - Note: The memory regions referenced by `source` and this buffer
|
||||
/// may overlap.
|
||||
///
|
||||
/// - Parameter source: A buffer containing the values to copy. The memory
|
||||
/// region underlying `source` must be initialized.
|
||||
/// - Returns: The index one past the last element of the buffer initialized
|
||||
/// by this function.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
internal func moveInitialize(fromContentsOf source: Self) -> Index {
|
||||
guard let sourceAddress = source.baseAddress, !source.isEmpty else {
|
||||
return startIndex
|
||||
}
|
||||
precondition(
|
||||
source.count <= self.count,
|
||||
"buffer cannot contain every element from source."
|
||||
)
|
||||
baseAddress?.moveInitialize(from: sourceAddress, count: source.count)
|
||||
return startIndex.advanced(by: source.count)
|
||||
}
|
||||
|
||||
/// Moves every element of an initialized source buffer into the
|
||||
/// uninitialized memory referenced by this buffer, leaving the source memory
|
||||
/// uninitialized and this buffer's memory initialized.
|
||||
///
|
||||
/// Prior to calling the `moveInitialize(fromContentsOf:)` method on a buffer,
|
||||
/// the memory it references must be uninitialized,
|
||||
/// or its `Element` type must be a trivial type. After the call,
|
||||
/// the memory referenced by the buffer up to, but not including,
|
||||
/// the returned index is initialized. The memory referenced by
|
||||
/// `source` is uninitialized after the function returns.
|
||||
/// The buffer must reference enough memory to accommodate
|
||||
/// `source.count` elements.
|
||||
///
|
||||
/// The returned index is the position of the next uninitialized element
|
||||
/// in the buffer, one past the index of the last element written.
|
||||
/// If `source` contains no elements, the returned index is equal to the
|
||||
/// buffer's `startIndex`. If `source` contains as many elements as the buffer
|
||||
/// can hold, the returned index is equal to the buffer's `endIndex`.
|
||||
///
|
||||
/// - Precondition: `self.count` >= `source.count`
|
||||
///
|
||||
/// - Note: The memory regions referenced by `source` and this buffer
|
||||
/// may overlap.
|
||||
///
|
||||
/// - Parameter source: A buffer containing the values to copy. The memory
|
||||
/// region underlying `source` must be initialized.
|
||||
/// - Returns: The index one past the last element of the buffer initialized
|
||||
/// by this function.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
internal func moveInitialize(fromContentsOf source: Slice<Self>) -> Index {
|
||||
return moveInitialize(fromContentsOf: Self(rebasing: source))
|
||||
}
|
||||
|
||||
/// Initializes the element at `index` to the given value.
|
||||
///
|
||||
/// The memory underlying the destination element must be uninitialized,
|
||||
/// or `Element` must be a trivial type. After a call to `initialize(to:)`,
|
||||
/// the memory underlying this element of the buffer is initialized.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - value: The value used to initialize the buffer element's memory.
|
||||
/// - index: The index of the element to initialize
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
internal func initializeElement(at index: Index, to value: Element) {
|
||||
assert(startIndex <= index && index < endIndex)
|
||||
let p = baseAddress.unsafelyUnwrapped.advanced(by: index)
|
||||
p.initialize(to: value)
|
||||
}
|
||||
|
||||
/// Retrieves and returns the element at `index`,
|
||||
/// leaving that element's underlying memory uninitialized.
|
||||
///
|
||||
/// The memory underlying the element at `index` must be initialized.
|
||||
/// After calling `moveElement(from:)`, the memory underlying this element
|
||||
/// of the buffer is uninitialized, and still bound to type `Element`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - index: The index of the buffer element to retrieve and deinitialize.
|
||||
/// - Returns: The instance referenced by this index in this buffer.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
internal func moveElement(from index: Index) -> Element {
|
||||
assert(startIndex <= index && index < endIndex)
|
||||
return baseAddress.unsafelyUnwrapped.advanced(by: index).move()
|
||||
}
|
||||
|
||||
/// Deinitializes the memory underlying the element at `index`.
|
||||
///
|
||||
/// The memory underlying the element at `index` must be initialized.
|
||||
/// After calling `deinitializeElement()`, the memory underlying this element
|
||||
/// of the buffer is uninitialized, and still bound to type `Element`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - index: The index of the buffer element to deinitialize.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
internal func deinitializeElement(at index: Index) {
|
||||
assert(startIndex <= index && index < endIndex)
|
||||
let p = baseAddress.unsafelyUnwrapped.advanced(by: index)
|
||||
p.deinitialize(count: 1)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if swift(<5.8)
|
||||
extension Slice {
|
||||
/// Initializes the buffer slice's memory with with
|
||||
/// every element of the source.
|
||||
///
|
||||
/// Prior to calling the `initialize(fromContentsOf:)` method
|
||||
/// on a buffer slice, the memory it references must be uninitialized,
|
||||
/// or the `Element` type must be a trivial type. After the call,
|
||||
/// the memory referenced by the buffer slice up to, but not including,
|
||||
/// the returned index is initialized.
|
||||
/// The buffer slice must reference enough memory to accommodate
|
||||
/// `source.count` elements.
|
||||
///
|
||||
/// The returned index is the index of the next uninitialized element
|
||||
/// in the buffer slice, one past the index of the last element written.
|
||||
/// If `source` contains no elements, the returned index is equal to
|
||||
/// the buffer slice's `startIndex`. If `source` contains as many elements
|
||||
/// as the buffer slice can hold, the returned index is equal to
|
||||
/// to the slice's `endIndex`.
|
||||
///
|
||||
/// - Precondition: `self.count` >= `source.count`
|
||||
///
|
||||
/// - Note: The memory regions referenced by `source` and this buffer slice
|
||||
/// must not overlap.
|
||||
///
|
||||
/// - Parameter source: A collection of elements to be used to
|
||||
/// initialize the buffer slice's storage.
|
||||
/// - Returns: The index one past the last element of the buffer slice
|
||||
/// initialized by this function.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
internal func initialize<C: Collection>(
|
||||
fromContentsOf source: C
|
||||
) -> Index where Base == UnsafeMutableBufferPointer<C.Element> {
|
||||
let buffer = Base(rebasing: self)
|
||||
let index = buffer.initialize(fromContentsOf: source)
|
||||
let distance = buffer.distance(from: buffer.startIndex, to: index)
|
||||
return startIndex.advanced(by: distance)
|
||||
}
|
||||
|
||||
/// Moves every element of an initialized source buffer into the
|
||||
/// uninitialized memory referenced by this buffer slice, leaving the
|
||||
/// source memory uninitialized and this buffer slice's memory initialized.
|
||||
///
|
||||
/// Prior to calling the `moveInitialize(fromContentsOf:)` method on a
|
||||
/// buffer slice, the memory it references must be uninitialized,
|
||||
/// or its `Element` type must be a trivial type. After the call,
|
||||
/// the memory referenced by the buffer slice up to, but not including,
|
||||
/// the returned index is initialized. The memory referenced by
|
||||
/// `source` is uninitialized after the function returns.
|
||||
/// The buffer slice must reference enough memory to accommodate
|
||||
/// `source.count` elements.
|
||||
///
|
||||
/// The returned index is the position of the next uninitialized element
|
||||
/// in the buffer slice, one past the index of the last element written.
|
||||
/// If `source` contains no elements, the returned index is equal to the
|
||||
/// slice's `startIndex`. If `source` contains as many elements as the slice
|
||||
/// can hold, the returned index is equal to the slice's `endIndex`.
|
||||
///
|
||||
/// - Note: The memory regions referenced by `source` and this buffer slice
|
||||
/// may overlap.
|
||||
///
|
||||
/// - Precondition: `self.count` >= `source.count`
|
||||
///
|
||||
/// - Parameter source: A buffer containing the values to copy.
|
||||
/// The memory region underlying `source` must be initialized.
|
||||
/// - Returns: The index one past the last element of the buffer slice
|
||||
/// initialized by this function.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
internal func moveInitialize<Element>(
|
||||
fromContentsOf source: UnsafeMutableBufferPointer<Element>
|
||||
) -> Index where Base == UnsafeMutableBufferPointer<Element> {
|
||||
let buffer = Base(rebasing: self)
|
||||
let index = buffer.moveInitialize(fromContentsOf: source)
|
||||
let distance = buffer.distance(from: buffer.startIndex, to: index)
|
||||
return startIndex.advanced(by: distance)
|
||||
}
|
||||
|
||||
/// Moves every element of an initialized source buffer slice into the
|
||||
/// uninitialized memory referenced by this buffer slice, leaving the
|
||||
/// source memory uninitialized and this buffer slice's memory initialized.
|
||||
///
|
||||
/// Prior to calling the `moveInitialize(fromContentsOf:)` method on a
|
||||
/// buffer slice, the memory it references must be uninitialized,
|
||||
/// or its `Element` type must be a trivial type. After the call,
|
||||
/// the memory referenced by the buffer slice up to, but not including,
|
||||
/// the returned index is initialized. The memory referenced by
|
||||
/// `source` is uninitialized after the function returns.
|
||||
/// The buffer slice must reference enough memory to accommodate
|
||||
/// `source.count` elements.
|
||||
///
|
||||
/// The returned index is the position of the next uninitialized element
|
||||
/// in the buffer slice, one past the index of the last element written.
|
||||
/// If `source` contains no elements, the returned index is equal to the
|
||||
/// slice's `startIndex`. If `source` contains as many elements as the slice
|
||||
/// can hold, the returned index is equal to the slice's `endIndex`.
|
||||
///
|
||||
/// - Note: The memory regions referenced by `source` and this buffer slice
|
||||
/// may overlap.
|
||||
///
|
||||
/// - Precondition: `self.count` >= `source.count`
|
||||
///
|
||||
/// - Parameter source: A buffer slice containing the values to copy.
|
||||
/// The memory region underlying `source` must be initialized.
|
||||
/// - Returns: The index one past the last element of the buffer slice
|
||||
/// initialized by this function.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
internal func moveInitialize<Element>(
|
||||
fromContentsOf source: Slice<UnsafeMutableBufferPointer<Element>>
|
||||
) -> Index where Base == UnsafeMutableBufferPointer<Element> {
|
||||
let buffer = Base(rebasing: self)
|
||||
let index = buffer.moveInitialize(fromContentsOf: source)
|
||||
let distance = buffer.distance(from: buffer.startIndex, to: index)
|
||||
return startIndex.advanced(by: distance)
|
||||
}
|
||||
|
||||
/// Deinitializes every instance in this buffer slice.
|
||||
///
|
||||
/// The region of memory underlying this buffer slice must be fully
|
||||
/// initialized. After calling `deinitialize(count:)`, the memory
|
||||
/// is uninitialized, but still bound to the `Element` type.
|
||||
///
|
||||
/// - Note: All buffer elements must already be initialized.
|
||||
///
|
||||
/// - Returns: A raw buffer to the same range of memory as this buffer.
|
||||
/// The range of memory is still bound to `Element`.
|
||||
@discardableResult
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
internal func deinitialize<Element>() -> UnsafeMutableRawBufferPointer
|
||||
where Base == UnsafeMutableBufferPointer<Element> {
|
||||
Base(rebasing: self).deinitialize()
|
||||
}
|
||||
|
||||
/// Initializes the element at `index` to the given value.
|
||||
///
|
||||
/// The memory underlying the destination element must be uninitialized,
|
||||
/// or `Element` must be a trivial type. After a call to `initialize(to:)`,
|
||||
/// the memory underlying this element of the buffer slice is initialized.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - value: The value used to initialize the buffer element's memory.
|
||||
/// - index: The index of the element to initialize
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
internal func initializeElement<Element>(at index: Int, to value: Element)
|
||||
where Base == UnsafeMutableBufferPointer<Element> {
|
||||
assert(startIndex <= index && index < endIndex)
|
||||
base.baseAddress.unsafelyUnwrapped.advanced(by: index).initialize(to: value)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if swift(<5.8)
|
||||
extension UnsafeMutableBufferPointer {
|
||||
/// Updates every element of this buffer's initialized memory.
|
||||
///
|
||||
/// The buffer’s memory must be initialized or its `Element` type
|
||||
/// must be a trivial type.
|
||||
///
|
||||
/// - Note: All buffer elements must already be initialized.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - repeatedValue: The value used when updating this pointer's memory.
|
||||
@_alwaysEmitIntoClient
|
||||
internal func update(repeating repeatedValue: Element) {
|
||||
guard let dstBase = baseAddress else { return }
|
||||
dstBase.update(repeating: repeatedValue, count: count)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if swift(<5.8)
|
||||
extension Slice {
|
||||
/// Updates every element of this buffer slice's initialized memory.
|
||||
///
|
||||
/// The buffer slice’s memory must be initialized or its `Element`
|
||||
/// must be a trivial type.
|
||||
///
|
||||
/// - Note: All buffer elements must already be initialized.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - repeatedValue: The value used when updating this pointer's memory.
|
||||
@_alwaysEmitIntoClient
|
||||
internal func update<Element>(repeating repeatedValue: Element)
|
||||
where Base == UnsafeMutableBufferPointer<Element> {
|
||||
Base(rebasing: self).update(repeating: repeatedValue)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#else // !COLLECTIONS_SINGLE_MODULE
|
||||
#if swift(<5.8)
|
||||
extension UnsafeMutableBufferPointer {
|
||||
/// Deinitializes every instance in this buffer.
|
||||
///
|
||||
/// The region of memory underlying this buffer must be fully initialized.
|
||||
/// After calling `deinitialize(count:)`, the memory is uninitialized,
|
||||
/// but still bound to the `Element` type.
|
||||
///
|
||||
/// - Note: All buffer elements must already be initialized.
|
||||
///
|
||||
/// - Returns: A raw buffer to the same range of memory as this buffer.
|
||||
/// The range of memory is still bound to `Element`.
|
||||
@discardableResult
|
||||
@inlinable
|
||||
public func deinitialize() -> UnsafeMutableRawBufferPointer {
|
||||
guard let start = baseAddress else { return .init(start: nil, count: 0) }
|
||||
start.deinitialize(count: count)
|
||||
return .init(start: UnsafeMutableRawPointer(start),
|
||||
count: count * MemoryLayout<Element>.stride)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Note: this is left unconditionally enabled because we need the SR14663 workaround. :-(
|
||||
extension UnsafeMutableBufferPointer {
|
||||
/// Initializes the buffer's memory with
|
||||
/// every element of the source.
|
||||
///
|
||||
/// Prior to calling the `initialize(fromContentsOf:)` method on a buffer,
|
||||
/// the memory referenced by the buffer must be uninitialized,
|
||||
/// or the `Element` type must be a trivial type. After the call,
|
||||
/// the memory referenced by the buffer up to, but not including,
|
||||
/// the returned index is initialized.
|
||||
/// The buffer must reference enough memory to accommodate
|
||||
/// `source.count` elements.
|
||||
///
|
||||
/// The returned index is the position of the next uninitialized element
|
||||
/// in the buffer, one past the index of the last element written.
|
||||
/// If `source` contains no elements, the returned index is equal to the
|
||||
/// buffer's `startIndex`. If `source` contains as many elements as the buffer
|
||||
/// can hold, the returned index is equal to the buffer's `endIndex`.
|
||||
///
|
||||
/// - Precondition: `self.count` >= `source.count`
|
||||
///
|
||||
/// - Note: The memory regions referenced by `source` and this buffer
|
||||
/// must not overlap.
|
||||
///
|
||||
/// - Parameter source: A collection of elements to be used to
|
||||
/// initialize the buffer's storage.
|
||||
/// - Returns: The index one past the last element of the buffer initialized
|
||||
/// by this function.
|
||||
@inlinable
|
||||
public func initialize<C: Collection>(
|
||||
fromContentsOf source: C
|
||||
) -> Index
|
||||
where C.Element == Element {
|
||||
let count: Int? = source.withContiguousStorageIfAvailable {
|
||||
guard let sourceAddress = $0.baseAddress, !$0.isEmpty else {
|
||||
return 0
|
||||
}
|
||||
precondition(
|
||||
$0.count <= self.count,
|
||||
"buffer cannot contain every element from source."
|
||||
)
|
||||
baseAddress?.initialize(from: sourceAddress, count: $0.count)
|
||||
return $0.count
|
||||
}
|
||||
if let count = count {
|
||||
return startIndex.advanced(by: count)
|
||||
}
|
||||
|
||||
var (iterator, copied) = source._copyContents(initializing: self)
|
||||
precondition(
|
||||
iterator.next() == nil,
|
||||
"buffer cannot contain every element from source."
|
||||
)
|
||||
return startIndex.advanced(by: copied)
|
||||
}
|
||||
}
|
||||
|
||||
#if swift(<5.8)
|
||||
extension UnsafeMutableBufferPointer {
|
||||
/// Moves every element of an initialized source buffer into the
|
||||
/// uninitialized memory referenced by this buffer, leaving the source memory
|
||||
/// uninitialized and this buffer's memory initialized.
|
||||
///
|
||||
/// Prior to calling the `moveInitialize(fromContentsOf:)` method on a buffer,
|
||||
/// the memory it references must be uninitialized,
|
||||
/// or its `Element` type must be a trivial type. After the call,
|
||||
/// the memory referenced by the buffer up to, but not including,
|
||||
/// the returned index is initialized. The memory referenced by
|
||||
/// `source` is uninitialized after the function returns.
|
||||
/// The buffer must reference enough memory to accommodate
|
||||
/// `source.count` elements.
|
||||
///
|
||||
/// The returned index is the position of the next uninitialized element
|
||||
/// in the buffer, one past the index of the last element written.
|
||||
/// If `source` contains no elements, the returned index is equal to the
|
||||
/// buffer's `startIndex`. If `source` contains as many elements as the buffer
|
||||
/// can hold, the returned index is equal to the buffer's `endIndex`.
|
||||
///
|
||||
/// - Precondition: `self.count` >= `source.count`
|
||||
///
|
||||
/// - Note: The memory regions referenced by `source` and this buffer
|
||||
/// may overlap.
|
||||
///
|
||||
/// - Parameter source: A buffer containing the values to copy. The memory
|
||||
/// region underlying `source` must be initialized.
|
||||
/// - Returns: The index one past the last element of the buffer initialized
|
||||
/// by this function.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
public func moveInitialize(fromContentsOf source: Self) -> Index {
|
||||
guard let sourceAddress = source.baseAddress, !source.isEmpty else {
|
||||
return startIndex
|
||||
}
|
||||
precondition(
|
||||
source.count <= self.count,
|
||||
"buffer cannot contain every element from source."
|
||||
)
|
||||
baseAddress?.moveInitialize(from: sourceAddress, count: source.count)
|
||||
return startIndex.advanced(by: source.count)
|
||||
}
|
||||
|
||||
/// Moves every element of an initialized source buffer into the
|
||||
/// uninitialized memory referenced by this buffer, leaving the source memory
|
||||
/// uninitialized and this buffer's memory initialized.
|
||||
///
|
||||
/// Prior to calling the `moveInitialize(fromContentsOf:)` method on a buffer,
|
||||
/// the memory it references must be uninitialized,
|
||||
/// or its `Element` type must be a trivial type. After the call,
|
||||
/// the memory referenced by the buffer up to, but not including,
|
||||
/// the returned index is initialized. The memory referenced by
|
||||
/// `source` is uninitialized after the function returns.
|
||||
/// The buffer must reference enough memory to accommodate
|
||||
/// `source.count` elements.
|
||||
///
|
||||
/// The returned index is the position of the next uninitialized element
|
||||
/// in the buffer, one past the index of the last element written.
|
||||
/// If `source` contains no elements, the returned index is equal to the
|
||||
/// buffer's `startIndex`. If `source` contains as many elements as the buffer
|
||||
/// can hold, the returned index is equal to the buffer's `endIndex`.
|
||||
///
|
||||
/// - Precondition: `self.count` >= `source.count`
|
||||
///
|
||||
/// - Note: The memory regions referenced by `source` and this buffer
|
||||
/// may overlap.
|
||||
///
|
||||
/// - Parameter source: A buffer containing the values to copy. The memory
|
||||
/// region underlying `source` must be initialized.
|
||||
/// - Returns: The index one past the last element of the buffer initialized
|
||||
/// by this function.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
public func moveInitialize(fromContentsOf source: Slice<Self>) -> Index {
|
||||
return moveInitialize(fromContentsOf: Self(rebasing: source))
|
||||
}
|
||||
|
||||
/// Initializes the element at `index` to the given value.
|
||||
///
|
||||
/// The memory underlying the destination element must be uninitialized,
|
||||
/// or `Element` must be a trivial type. After a call to `initialize(to:)`,
|
||||
/// the memory underlying this element of the buffer is initialized.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - value: The value used to initialize the buffer element's memory.
|
||||
/// - index: The index of the element to initialize
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
public func initializeElement(at index: Index, to value: Element) {
|
||||
assert(startIndex <= index && index < endIndex)
|
||||
let p = baseAddress.unsafelyUnwrapped.advanced(by: index)
|
||||
p.initialize(to: value)
|
||||
}
|
||||
|
||||
/// Retrieves and returns the element at `index`,
|
||||
/// leaving that element's underlying memory uninitialized.
|
||||
///
|
||||
/// The memory underlying the element at `index` must be initialized.
|
||||
/// After calling `moveElement(from:)`, the memory underlying this element
|
||||
/// of the buffer is uninitialized, and still bound to type `Element`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - index: The index of the buffer element to retrieve and deinitialize.
|
||||
/// - Returns: The instance referenced by this index in this buffer.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
public func moveElement(from index: Index) -> Element {
|
||||
assert(startIndex <= index && index < endIndex)
|
||||
return baseAddress.unsafelyUnwrapped.advanced(by: index).move()
|
||||
}
|
||||
|
||||
/// Deinitializes the memory underlying the element at `index`.
|
||||
///
|
||||
/// The memory underlying the element at `index` must be initialized.
|
||||
/// After calling `deinitializeElement()`, the memory underlying this element
|
||||
/// of the buffer is uninitialized, and still bound to type `Element`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - index: The index of the buffer element to deinitialize.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
public func deinitializeElement(at index: Index) {
|
||||
assert(startIndex <= index && index < endIndex)
|
||||
let p = baseAddress.unsafelyUnwrapped.advanced(by: index)
|
||||
p.deinitialize(count: 1)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if swift(<5.8)
|
||||
extension Slice {
|
||||
/// Initializes the buffer slice's memory with with
|
||||
/// every element of the source.
|
||||
///
|
||||
/// Prior to calling the `initialize(fromContentsOf:)` method
|
||||
/// on a buffer slice, the memory it references must be uninitialized,
|
||||
/// or the `Element` type must be a trivial type. After the call,
|
||||
/// the memory referenced by the buffer slice up to, but not including,
|
||||
/// the returned index is initialized.
|
||||
/// The buffer slice must reference enough memory to accommodate
|
||||
/// `source.count` elements.
|
||||
///
|
||||
/// The returned index is the index of the next uninitialized element
|
||||
/// in the buffer slice, one past the index of the last element written.
|
||||
/// If `source` contains no elements, the returned index is equal to
|
||||
/// the buffer slice's `startIndex`. If `source` contains as many elements
|
||||
/// as the buffer slice can hold, the returned index is equal to
|
||||
/// to the slice's `endIndex`.
|
||||
///
|
||||
/// - Precondition: `self.count` >= `source.count`
|
||||
///
|
||||
/// - Note: The memory regions referenced by `source` and this buffer slice
|
||||
/// must not overlap.
|
||||
///
|
||||
/// - Parameter source: A collection of elements to be used to
|
||||
/// initialize the buffer slice's storage.
|
||||
/// - Returns: The index one past the last element of the buffer slice
|
||||
/// initialized by this function.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
public func initialize<C: Collection>(
|
||||
fromContentsOf source: C
|
||||
) -> Index where Base == UnsafeMutableBufferPointer<C.Element> {
|
||||
let buffer = Base(rebasing: self)
|
||||
let index = buffer.initialize(fromContentsOf: source)
|
||||
let distance = buffer.distance(from: buffer.startIndex, to: index)
|
||||
return startIndex.advanced(by: distance)
|
||||
}
|
||||
|
||||
/// Moves every element of an initialized source buffer into the
|
||||
/// uninitialized memory referenced by this buffer slice, leaving the
|
||||
/// source memory uninitialized and this buffer slice's memory initialized.
|
||||
///
|
||||
/// Prior to calling the `moveInitialize(fromContentsOf:)` method on a
|
||||
/// buffer slice, the memory it references must be uninitialized,
|
||||
/// or its `Element` type must be a trivial type. After the call,
|
||||
/// the memory referenced by the buffer slice up to, but not including,
|
||||
/// the returned index is initialized. The memory referenced by
|
||||
/// `source` is uninitialized after the function returns.
|
||||
/// The buffer slice must reference enough memory to accommodate
|
||||
/// `source.count` elements.
|
||||
///
|
||||
/// The returned index is the position of the next uninitialized element
|
||||
/// in the buffer slice, one past the index of the last element written.
|
||||
/// If `source` contains no elements, the returned index is equal to the
|
||||
/// slice's `startIndex`. If `source` contains as many elements as the slice
|
||||
/// can hold, the returned index is equal to the slice's `endIndex`.
|
||||
///
|
||||
/// - Note: The memory regions referenced by `source` and this buffer slice
|
||||
/// may overlap.
|
||||
///
|
||||
/// - Precondition: `self.count` >= `source.count`
|
||||
///
|
||||
/// - Parameter source: A buffer containing the values to copy.
|
||||
/// The memory region underlying `source` must be initialized.
|
||||
/// - Returns: The index one past the last element of the buffer slice
|
||||
/// initialized by this function.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
public func moveInitialize<Element>(
|
||||
fromContentsOf source: UnsafeMutableBufferPointer<Element>
|
||||
) -> Index where Base == UnsafeMutableBufferPointer<Element> {
|
||||
let buffer = Base(rebasing: self)
|
||||
let index = buffer.moveInitialize(fromContentsOf: source)
|
||||
let distance = buffer.distance(from: buffer.startIndex, to: index)
|
||||
return startIndex.advanced(by: distance)
|
||||
}
|
||||
|
||||
/// Moves every element of an initialized source buffer slice into the
|
||||
/// uninitialized memory referenced by this buffer slice, leaving the
|
||||
/// source memory uninitialized and this buffer slice's memory initialized.
|
||||
///
|
||||
/// Prior to calling the `moveInitialize(fromContentsOf:)` method on a
|
||||
/// buffer slice, the memory it references must be uninitialized,
|
||||
/// or its `Element` type must be a trivial type. After the call,
|
||||
/// the memory referenced by the buffer slice up to, but not including,
|
||||
/// the returned index is initialized. The memory referenced by
|
||||
/// `source` is uninitialized after the function returns.
|
||||
/// The buffer slice must reference enough memory to accommodate
|
||||
/// `source.count` elements.
|
||||
///
|
||||
/// The returned index is the position of the next uninitialized element
|
||||
/// in the buffer slice, one past the index of the last element written.
|
||||
/// If `source` contains no elements, the returned index is equal to the
|
||||
/// slice's `startIndex`. If `source` contains as many elements as the slice
|
||||
/// can hold, the returned index is equal to the slice's `endIndex`.
|
||||
///
|
||||
/// - Note: The memory regions referenced by `source` and this buffer slice
|
||||
/// may overlap.
|
||||
///
|
||||
/// - Precondition: `self.count` >= `source.count`
|
||||
///
|
||||
/// - Parameter source: A buffer slice containing the values to copy.
|
||||
/// The memory region underlying `source` must be initialized.
|
||||
/// - Returns: The index one past the last element of the buffer slice
|
||||
/// initialized by this function.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
public func moveInitialize<Element>(
|
||||
fromContentsOf source: Slice<UnsafeMutableBufferPointer<Element>>
|
||||
) -> Index where Base == UnsafeMutableBufferPointer<Element> {
|
||||
let buffer = Base(rebasing: self)
|
||||
let index = buffer.moveInitialize(fromContentsOf: source)
|
||||
let distance = buffer.distance(from: buffer.startIndex, to: index)
|
||||
return startIndex.advanced(by: distance)
|
||||
}
|
||||
|
||||
/// Deinitializes every instance in this buffer slice.
|
||||
///
|
||||
/// The region of memory underlying this buffer slice must be fully
|
||||
/// initialized. After calling `deinitialize(count:)`, the memory
|
||||
/// is uninitialized, but still bound to the `Element` type.
|
||||
///
|
||||
/// - Note: All buffer elements must already be initialized.
|
||||
///
|
||||
/// - Returns: A raw buffer to the same range of memory as this buffer.
|
||||
/// The range of memory is still bound to `Element`.
|
||||
@discardableResult
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
public func deinitialize<Element>() -> UnsafeMutableRawBufferPointer
|
||||
where Base == UnsafeMutableBufferPointer<Element> {
|
||||
Base(rebasing: self).deinitialize()
|
||||
}
|
||||
|
||||
/// Initializes the element at `index` to the given value.
|
||||
///
|
||||
/// The memory underlying the destination element must be uninitialized,
|
||||
/// or `Element` must be a trivial type. After a call to `initialize(to:)`,
|
||||
/// the memory underlying this element of the buffer slice is initialized.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - value: The value used to initialize the buffer element's memory.
|
||||
/// - index: The index of the element to initialize
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
public func initializeElement<Element>(at index: Int, to value: Element)
|
||||
where Base == UnsafeMutableBufferPointer<Element> {
|
||||
assert(startIndex <= index && index < endIndex)
|
||||
base.baseAddress.unsafelyUnwrapped.advanced(by: index).initialize(to: value)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if swift(<5.8)
|
||||
extension UnsafeMutableBufferPointer {
|
||||
/// Updates every element of this buffer's initialized memory.
|
||||
///
|
||||
/// The buffer’s memory must be initialized or its `Element` type
|
||||
/// must be a trivial type.
|
||||
///
|
||||
/// - Note: All buffer elements must already be initialized.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - repeatedValue: The value used when updating this pointer's memory.
|
||||
@_alwaysEmitIntoClient
|
||||
public func update(repeating repeatedValue: Element) {
|
||||
guard let dstBase = baseAddress else { return }
|
||||
dstBase.update(repeating: repeatedValue, count: count)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if swift(<5.8)
|
||||
extension Slice {
|
||||
/// Updates every element of this buffer slice's initialized memory.
|
||||
///
|
||||
/// The buffer slice’s memory must be initialized or its `Element`
|
||||
/// must be a trivial type.
|
||||
///
|
||||
/// - Note: All buffer elements must already be initialized.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - repeatedValue: The value used when updating this pointer's memory.
|
||||
@_alwaysEmitIntoClient
|
||||
public func update<Element>(repeating repeatedValue: Element)
|
||||
where Base == UnsafeMutableBufferPointer<Element> {
|
||||
Base(rebasing: self).update(repeating: repeatedValue)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif // COLLECTIONS_SINGLE_MODULE
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Swift Collections open source project
|
||||
//
|
||||
// Copyright (c) 2022 - 2024 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
|
||||
// #############################################################################
|
||||
// # #
|
||||
// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. #
|
||||
// # #
|
||||
// #############################################################################
|
||||
|
||||
|
||||
|
||||
// In single module mode, we need these declarations to be internal,
|
||||
// but in regular builds we want them to be public. Unfortunately
|
||||
// the current best way to do this is to duplicate all definitions.
|
||||
#if COLLECTIONS_SINGLE_MODULE
|
||||
#if swift(<5.8)
|
||||
extension UnsafeMutablePointer {
|
||||
/// Update this pointer's initialized memory with the specified number of
|
||||
/// consecutive copies of the given value.
|
||||
///
|
||||
/// The region of memory starting at this pointer and covering `count`
|
||||
/// instances of the pointer's `Pointee` type must be initialized or
|
||||
/// `Pointee` must be a trivial type. After calling
|
||||
/// `update(repeating:count:)`, the region is initialized.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - repeatedValue: The value used when updating this pointer's memory.
|
||||
/// - count: The number of consecutive elements to update.
|
||||
/// `count` must not be negative.
|
||||
@_alwaysEmitIntoClient
|
||||
internal func update(repeating repeatedValue: Pointee, count: Int) {
|
||||
assert(count >= 0, "UnsafeMutablePointer.update(repeating:count:) with negative count")
|
||||
for i in 0 ..< count {
|
||||
self[i] = repeatedValue
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#else // !COLLECTIONS_SINGLE_MODULE
|
||||
#if swift(<5.8)
|
||||
extension UnsafeMutablePointer {
|
||||
/// Update this pointer's initialized memory with the specified number of
|
||||
/// consecutive copies of the given value.
|
||||
///
|
||||
/// The region of memory starting at this pointer and covering `count`
|
||||
/// instances of the pointer's `Pointee` type must be initialized or
|
||||
/// `Pointee` must be a trivial type. After calling
|
||||
/// `update(repeating:count:)`, the region is initialized.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - repeatedValue: The value used when updating this pointer's memory.
|
||||
/// - count: The number of consecutive elements to update.
|
||||
/// `count` must not be negative.
|
||||
@_alwaysEmitIntoClient
|
||||
public func update(repeating repeatedValue: Pointee, count: Int) {
|
||||
assert(count >= 0, "UnsafeMutablePointer.update(repeating:count:) with negative count")
|
||||
for i in 0 ..< count {
|
||||
self[i] = repeatedValue
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif // COLLECTIONS_SINGLE_MODULE
|
||||
-164
@@ -1,164 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Swift Collections open source project
|
||||
//
|
||||
// Copyright (c) 2022 - 2024 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
|
||||
// #############################################################################
|
||||
// # #
|
||||
// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. #
|
||||
// # #
|
||||
// #############################################################################
|
||||
|
||||
|
||||
|
||||
// In single module mode, we need these declarations to be internal,
|
||||
// but in regular builds we want them to be public. Unfortunately
|
||||
// the current best way to do this is to duplicate all definitions.
|
||||
#if COLLECTIONS_SINGLE_MODULE
|
||||
#if compiler(<5.7) || (os(macOS) && compiler(<5.8)) // SE-0334
|
||||
extension UnsafeRawPointer {
|
||||
/// Obtain the next pointer properly aligned to store a value of type `T`.
|
||||
///
|
||||
/// If `self` is properly aligned for accessing `T`,
|
||||
/// this function returns `self`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - type: the type to be stored at the returned address.
|
||||
/// - Returns: a pointer properly aligned to store a value of type `T`.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
internal func alignedUp<T>(for type: T.Type) -> Self {
|
||||
let mask = UInt(MemoryLayout<T>.alignment) &- 1
|
||||
let bits = (UInt(bitPattern: self) &+ mask) & ~mask
|
||||
return Self(bitPattern: bits)!
|
||||
}
|
||||
|
||||
/// Obtain the preceding pointer properly aligned to store a value of type `T`.
|
||||
///
|
||||
/// If `self` is properly aligned for accessing `T`,
|
||||
/// this function returns `self`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - type: the type to be stored at the returned address.
|
||||
/// - Returns: a pointer properly aligned to store a value of type `T`.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
internal func alignedDown<T>(for type: T.Type) -> Self {
|
||||
let mask = UInt(MemoryLayout<T>.alignment) &- 1
|
||||
let bits = UInt(bitPattern: self) & ~mask
|
||||
return Self(bitPattern: bits)!
|
||||
}
|
||||
}
|
||||
|
||||
extension UnsafeMutableRawPointer {
|
||||
/// Obtain the next pointer properly aligned to store a value of type `T`.
|
||||
///
|
||||
/// If `self` is properly aligned for accessing `T`,
|
||||
/// this function returns `self`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - type: the type to be stored at the returned address.
|
||||
/// - Returns: a pointer properly aligned to store a value of type `T`.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
internal func alignedUp<T>(for type: T.Type) -> Self {
|
||||
let mask = UInt(MemoryLayout<T>.alignment) &- 1
|
||||
let bits = (UInt(bitPattern: self) &+ mask) & ~mask
|
||||
return Self(bitPattern: bits)!
|
||||
}
|
||||
|
||||
/// Obtain the preceding pointer properly aligned to store a value of type `T`.
|
||||
///
|
||||
/// If `self` is properly aligned for accessing `T`,
|
||||
/// this function returns `self`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - type: the type to be stored at the returned address.
|
||||
/// - Returns: a pointer properly aligned to store a value of type `T`.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
internal func alignedDown<T>(for type: T.Type) -> Self {
|
||||
let mask = UInt(MemoryLayout<T>.alignment) &- 1
|
||||
let bits = UInt(bitPattern: self) & ~mask
|
||||
return Self(bitPattern: bits)!
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#else // !COLLECTIONS_SINGLE_MODULE
|
||||
#if compiler(<5.7) || (os(macOS) && compiler(<5.8)) // SE-0334
|
||||
extension UnsafeRawPointer {
|
||||
/// Obtain the next pointer properly aligned to store a value of type `T`.
|
||||
///
|
||||
/// If `self` is properly aligned for accessing `T`,
|
||||
/// this function returns `self`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - type: the type to be stored at the returned address.
|
||||
/// - Returns: a pointer properly aligned to store a value of type `T`.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
public func alignedUp<T>(for type: T.Type) -> Self {
|
||||
let mask = UInt(MemoryLayout<T>.alignment) &- 1
|
||||
let bits = (UInt(bitPattern: self) &+ mask) & ~mask
|
||||
return Self(bitPattern: bits)!
|
||||
}
|
||||
|
||||
/// Obtain the preceding pointer properly aligned to store a value of type `T`.
|
||||
///
|
||||
/// If `self` is properly aligned for accessing `T`,
|
||||
/// this function returns `self`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - type: the type to be stored at the returned address.
|
||||
/// - Returns: a pointer properly aligned to store a value of type `T`.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
public func alignedDown<T>(for type: T.Type) -> Self {
|
||||
let mask = UInt(MemoryLayout<T>.alignment) &- 1
|
||||
let bits = UInt(bitPattern: self) & ~mask
|
||||
return Self(bitPattern: bits)!
|
||||
}
|
||||
}
|
||||
|
||||
extension UnsafeMutableRawPointer {
|
||||
/// Obtain the next pointer properly aligned to store a value of type `T`.
|
||||
///
|
||||
/// If `self` is properly aligned for accessing `T`,
|
||||
/// this function returns `self`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - type: the type to be stored at the returned address.
|
||||
/// - Returns: a pointer properly aligned to store a value of type `T`.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
public func alignedUp<T>(for type: T.Type) -> Self {
|
||||
let mask = UInt(MemoryLayout<T>.alignment) &- 1
|
||||
let bits = (UInt(bitPattern: self) &+ mask) & ~mask
|
||||
return Self(bitPattern: bits)!
|
||||
}
|
||||
|
||||
/// Obtain the preceding pointer properly aligned to store a value of type `T`.
|
||||
///
|
||||
/// If `self` is properly aligned for accessing `T`,
|
||||
/// this function returns `self`.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - type: the type to be stored at the returned address.
|
||||
/// - Returns: a pointer properly aligned to store a value of type `T`.
|
||||
@inlinable
|
||||
@_alwaysEmitIntoClient
|
||||
public func alignedDown<T>(for type: T.Type) -> Self {
|
||||
let mask = UInt(MemoryLayout<T>.alignment) &- 1
|
||||
let bits = UInt(bitPattern: self) & ~mask
|
||||
return Self(bitPattern: bits)!
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif // COLLECTIONS_SINGLE_MODULE
|
||||
@@ -1,34 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Swift Collections open source project
|
||||
//
|
||||
// Copyright (c) 2023 - 2024 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
%{
|
||||
from gyb_utils import *
|
||||
}%
|
||||
${autogenerated_warning()}
|
||||
|
||||
% for modifier in visibility_levels:
|
||||
${visibility_boilerplate(modifier)}
|
||||
/// Returns `x` as its concrete type `U`, or `nil` if `x` has a different
|
||||
/// concrete type.
|
||||
///
|
||||
/// This cast can be useful for dispatching to specializations of generic
|
||||
/// functions.
|
||||
@_transparent
|
||||
@inlinable
|
||||
${modifier} func _specialize<T, U>(_ x: T, for: U.Type) -> U? {
|
||||
// Note: this was ported from recent versions of the Swift stdlib.
|
||||
guard T.self == U.self else {
|
||||
return nil
|
||||
}
|
||||
return _identityCast(x, to: U.self)
|
||||
}
|
||||
% end
|
||||
${visibility_boilerplate("end")}
|
||||
@@ -18,7 +18,7 @@ ${autogenerated_warning()}
|
||||
${visibility_boilerplate(modifier)}
|
||||
extension UnsafeMutableBufferPointer {
|
||||
@inlinable
|
||||
public func initialize(fromContentsOf source: Self) -> Index {
|
||||
${modifier} func initialize(fromContentsOf source: Self) -> Index {
|
||||
guard source.count > 0 else { return 0 }
|
||||
precondition(
|
||||
source.count <= self.count,
|
||||
@@ -30,7 +30,7 @@ extension UnsafeMutableBufferPointer {
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func initialize(fromContentsOf source: Slice<Self>) -> Index {
|
||||
${modifier} func initialize(fromContentsOf source: Slice<Self>) -> Index {
|
||||
let sourceCount = source.count
|
||||
guard sourceCount > 0 else { return 0 }
|
||||
precondition(
|
||||
@@ -45,7 +45,7 @@ extension UnsafeMutableBufferPointer {
|
||||
|
||||
extension Slice {
|
||||
@inlinable @inline(__always)
|
||||
public func initialize<Element>(
|
||||
${modifier} func initialize<Element>(
|
||||
fromContentsOf source: UnsafeMutableBufferPointer<Element>
|
||||
) -> Index
|
||||
where Base == UnsafeMutableBufferPointer<Element>
|
||||
@@ -56,7 +56,7 @@ extension Slice {
|
||||
}
|
||||
|
||||
@inlinable @inline(__always)
|
||||
public func initialize<Element>(
|
||||
${modifier} func initialize<Element>(
|
||||
fromContentsOf source: Slice<UnsafeMutableBufferPointer<Element>>
|
||||
) -> Index
|
||||
where Base == UnsafeMutableBufferPointer<Element>
|
||||
@@ -69,7 +69,7 @@ extension Slice {
|
||||
|
||||
extension UnsafeMutableBufferPointer {
|
||||
@inlinable @inline(__always)
|
||||
public func initializeAll<C: Collection>(
|
||||
${modifier} func initializeAll<C: Collection>(
|
||||
fromContentsOf source: C
|
||||
) where C.Element == Element {
|
||||
let i = self.initialize(fromContentsOf: source)
|
||||
@@ -77,25 +77,25 @@ extension UnsafeMutableBufferPointer {
|
||||
}
|
||||
|
||||
@inlinable @inline(__always)
|
||||
public func initializeAll(fromContentsOf source: Self) {
|
||||
${modifier} func initializeAll(fromContentsOf source: Self) {
|
||||
let i = self.initialize(fromContentsOf: source)
|
||||
assert(i == self.endIndex)
|
||||
}
|
||||
|
||||
@inlinable @inline(__always)
|
||||
public func initializeAll(fromContentsOf source: Slice<Self>) {
|
||||
${modifier} func initializeAll(fromContentsOf source: Slice<Self>) {
|
||||
let i = self.initialize(fromContentsOf: source)
|
||||
assert(i == self.endIndex)
|
||||
}
|
||||
|
||||
@inlinable @inline(__always)
|
||||
public func moveInitializeAll(fromContentsOf source: Self) {
|
||||
${modifier} func moveInitializeAll(fromContentsOf source: Self) {
|
||||
let i = self.moveInitialize(fromContentsOf: source)
|
||||
assert(i == self.endIndex)
|
||||
}
|
||||
|
||||
@inlinable @inline(__always)
|
||||
public func moveInitializeAll(fromContentsOf source: Slice<Self>) {
|
||||
${modifier} func moveInitializeAll(fromContentsOf source: Slice<Self>) {
|
||||
let i = self.moveInitialize(fromContentsOf: source)
|
||||
assert(i == self.endIndex)
|
||||
}
|
||||
@@ -103,7 +103,7 @@ extension UnsafeMutableBufferPointer {
|
||||
|
||||
extension Slice {
|
||||
@inlinable @inline(__always)
|
||||
public func initializeAll<C: Collection>(
|
||||
${modifier} func initializeAll<C: Collection>(
|
||||
fromContentsOf source: C
|
||||
) where Base == UnsafeMutableBufferPointer<C.Element> {
|
||||
let i = self.initialize(fromContentsOf: source)
|
||||
@@ -111,7 +111,7 @@ extension Slice {
|
||||
}
|
||||
|
||||
@inlinable @inline(__always)
|
||||
public func initializeAll<Element>(
|
||||
${modifier} func initializeAll<Element>(
|
||||
fromContentsOf source: UnsafeMutableBufferPointer<Element>
|
||||
) where Base == UnsafeMutableBufferPointer<Element> {
|
||||
let target = UnsafeMutableBufferPointer(rebasing: self)
|
||||
@@ -119,7 +119,7 @@ extension Slice {
|
||||
}
|
||||
|
||||
@inlinable @inline(__always)
|
||||
public func initializeAll<Element>(
|
||||
${modifier} func initializeAll<Element>(
|
||||
fromContentsOf source: Slice<UnsafeMutableBufferPointer<Element>>
|
||||
) where Base == UnsafeMutableBufferPointer<Element> {
|
||||
let target = UnsafeMutableBufferPointer(rebasing: self)
|
||||
@@ -127,7 +127,7 @@ extension Slice {
|
||||
}
|
||||
|
||||
@inlinable @inline(__always)
|
||||
public func moveInitializeAll<Element>(
|
||||
${modifier} func moveInitializeAll<Element>(
|
||||
fromContentsOf source: UnsafeMutableBufferPointer<Element>
|
||||
) where Base == UnsafeMutableBufferPointer<Element> {
|
||||
let target = UnsafeMutableBufferPointer(rebasing: self)
|
||||
@@ -135,7 +135,7 @@ extension Slice {
|
||||
}
|
||||
|
||||
@inlinable @inline(__always)
|
||||
public func moveInitializeAll<Element>(
|
||||
${modifier} func moveInitializeAll<Element>(
|
||||
fromContentsOf source: Slice<UnsafeMutableBufferPointer<Element>>
|
||||
) where Base == UnsafeMutableBufferPointer<Element> {
|
||||
let target = UnsafeMutableBufferPointer(rebasing: self)
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the Swift Collections open source project
|
||||
//
|
||||
// Copyright (c) 2023 - 2024 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
|
||||
// #############################################################################
|
||||
// # #
|
||||
// # DO NOT EDIT THIS FILE; IT IS AUTOGENERATED. #
|
||||
// # #
|
||||
// #############################################################################
|
||||
|
||||
|
||||
|
||||
// In single module mode, we need these declarations to be internal,
|
||||
// but in regular builds we want them to be public. Unfortunately
|
||||
// the current best way to do this is to duplicate all definitions.
|
||||
#if COLLECTIONS_SINGLE_MODULE
|
||||
/// Returns `x` as its concrete type `U`, or `nil` if `x` has a different
|
||||
/// concrete type.
|
||||
///
|
||||
/// This cast can be useful for dispatching to specializations of generic
|
||||
/// functions.
|
||||
@_transparent
|
||||
@inlinable
|
||||
internal func _specialize<T, U>(_ x: T, for: U.Type) -> U? {
|
||||
// Note: this was ported from recent versions of the Swift stdlib.
|
||||
guard T.self == U.self else {
|
||||
return nil
|
||||
}
|
||||
return _identityCast(x, to: U.self)
|
||||
}
|
||||
#else // !COLLECTIONS_SINGLE_MODULE
|
||||
/// Returns `x` as its concrete type `U`, or `nil` if `x` has a different
|
||||
/// concrete type.
|
||||
///
|
||||
/// This cast can be useful for dispatching to specializations of generic
|
||||
/// functions.
|
||||
@_transparent
|
||||
@inlinable
|
||||
public func _specialize<T, U>(_ x: T, for: U.Type) -> U? {
|
||||
// Note: this was ported from recent versions of the Swift stdlib.
|
||||
guard T.self == U.self else {
|
||||
return nil
|
||||
}
|
||||
return _identityCast(x, to: U.self)
|
||||
}
|
||||
#endif // COLLECTIONS_SINGLE_MODULE
|
||||
+14
-14
@@ -24,7 +24,7 @@
|
||||
#if COLLECTIONS_SINGLE_MODULE
|
||||
extension UnsafeMutableBufferPointer {
|
||||
@inlinable
|
||||
public func initialize(fromContentsOf source: Self) -> Index {
|
||||
internal func initialize(fromContentsOf source: Self) -> Index {
|
||||
guard source.count > 0 else { return 0 }
|
||||
precondition(
|
||||
source.count <= self.count,
|
||||
@@ -36,7 +36,7 @@ extension UnsafeMutableBufferPointer {
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func initialize(fromContentsOf source: Slice<Self>) -> Index {
|
||||
internal func initialize(fromContentsOf source: Slice<Self>) -> Index {
|
||||
let sourceCount = source.count
|
||||
guard sourceCount > 0 else { return 0 }
|
||||
precondition(
|
||||
@@ -51,7 +51,7 @@ extension UnsafeMutableBufferPointer {
|
||||
|
||||
extension Slice {
|
||||
@inlinable @inline(__always)
|
||||
public func initialize<Element>(
|
||||
internal func initialize<Element>(
|
||||
fromContentsOf source: UnsafeMutableBufferPointer<Element>
|
||||
) -> Index
|
||||
where Base == UnsafeMutableBufferPointer<Element>
|
||||
@@ -62,7 +62,7 @@ extension Slice {
|
||||
}
|
||||
|
||||
@inlinable @inline(__always)
|
||||
public func initialize<Element>(
|
||||
internal func initialize<Element>(
|
||||
fromContentsOf source: Slice<UnsafeMutableBufferPointer<Element>>
|
||||
) -> Index
|
||||
where Base == UnsafeMutableBufferPointer<Element>
|
||||
@@ -75,7 +75,7 @@ extension Slice {
|
||||
|
||||
extension UnsafeMutableBufferPointer {
|
||||
@inlinable @inline(__always)
|
||||
public func initializeAll<C: Collection>(
|
||||
internal func initializeAll<C: Collection>(
|
||||
fromContentsOf source: C
|
||||
) where C.Element == Element {
|
||||
let i = self.initialize(fromContentsOf: source)
|
||||
@@ -83,25 +83,25 @@ extension UnsafeMutableBufferPointer {
|
||||
}
|
||||
|
||||
@inlinable @inline(__always)
|
||||
public func initializeAll(fromContentsOf source: Self) {
|
||||
internal func initializeAll(fromContentsOf source: Self) {
|
||||
let i = self.initialize(fromContentsOf: source)
|
||||
assert(i == self.endIndex)
|
||||
}
|
||||
|
||||
@inlinable @inline(__always)
|
||||
public func initializeAll(fromContentsOf source: Slice<Self>) {
|
||||
internal func initializeAll(fromContentsOf source: Slice<Self>) {
|
||||
let i = self.initialize(fromContentsOf: source)
|
||||
assert(i == self.endIndex)
|
||||
}
|
||||
|
||||
@inlinable @inline(__always)
|
||||
public func moveInitializeAll(fromContentsOf source: Self) {
|
||||
internal func moveInitializeAll(fromContentsOf source: Self) {
|
||||
let i = self.moveInitialize(fromContentsOf: source)
|
||||
assert(i == self.endIndex)
|
||||
}
|
||||
|
||||
@inlinable @inline(__always)
|
||||
public func moveInitializeAll(fromContentsOf source: Slice<Self>) {
|
||||
internal func moveInitializeAll(fromContentsOf source: Slice<Self>) {
|
||||
let i = self.moveInitialize(fromContentsOf: source)
|
||||
assert(i == self.endIndex)
|
||||
}
|
||||
@@ -109,7 +109,7 @@ extension UnsafeMutableBufferPointer {
|
||||
|
||||
extension Slice {
|
||||
@inlinable @inline(__always)
|
||||
public func initializeAll<C: Collection>(
|
||||
internal func initializeAll<C: Collection>(
|
||||
fromContentsOf source: C
|
||||
) where Base == UnsafeMutableBufferPointer<C.Element> {
|
||||
let i = self.initialize(fromContentsOf: source)
|
||||
@@ -117,7 +117,7 @@ extension Slice {
|
||||
}
|
||||
|
||||
@inlinable @inline(__always)
|
||||
public func initializeAll<Element>(
|
||||
internal func initializeAll<Element>(
|
||||
fromContentsOf source: UnsafeMutableBufferPointer<Element>
|
||||
) where Base == UnsafeMutableBufferPointer<Element> {
|
||||
let target = UnsafeMutableBufferPointer(rebasing: self)
|
||||
@@ -125,7 +125,7 @@ extension Slice {
|
||||
}
|
||||
|
||||
@inlinable @inline(__always)
|
||||
public func initializeAll<Element>(
|
||||
internal func initializeAll<Element>(
|
||||
fromContentsOf source: Slice<UnsafeMutableBufferPointer<Element>>
|
||||
) where Base == UnsafeMutableBufferPointer<Element> {
|
||||
let target = UnsafeMutableBufferPointer(rebasing: self)
|
||||
@@ -133,7 +133,7 @@ extension Slice {
|
||||
}
|
||||
|
||||
@inlinable @inline(__always)
|
||||
public func moveInitializeAll<Element>(
|
||||
internal func moveInitializeAll<Element>(
|
||||
fromContentsOf source: UnsafeMutableBufferPointer<Element>
|
||||
) where Base == UnsafeMutableBufferPointer<Element> {
|
||||
let target = UnsafeMutableBufferPointer(rebasing: self)
|
||||
@@ -141,7 +141,7 @@ extension Slice {
|
||||
}
|
||||
|
||||
@inlinable @inline(__always)
|
||||
public func moveInitializeAll<Element>(
|
||||
internal func moveInitializeAll<Element>(
|
||||
fromContentsOf source: Slice<UnsafeMutableBufferPointer<Element>>
|
||||
) where Base == UnsafeMutableBufferPointer<Element> {
|
||||
let target = UnsafeMutableBufferPointer(rebasing: self)
|
||||
|
||||
Reference in new issue
Block a user