diff --git a/Sources/BasicContainers/RigidArray/RigidArray.swift b/Sources/BasicContainers/RigidArray/RigidArray.swift index 3d96e798..ccc8be1d 100644 --- a/Sources/BasicContainers/RigidArray/RigidArray.swift +++ b/Sources/BasicContainers/RigidArray/RigidArray.swift @@ -470,11 +470,11 @@ extension RigidArray { /// instance with just enough capacity to hold all its elements. /// /// - Complexity: O(`count`) - @inlinable - public func copy() -> Self { - copy(capacity: count) + @_alwaysEmitIntoClient + public func clone() -> Self { + clone(capacity: self.count) } - + /// Copy the contents of this array into a newly allocated rigid array /// instance with the specified capacity. /// @@ -483,7 +483,7 @@ extension RigidArray { /// /// - Complexity: O(`count`) @inlinable - public func copy(capacity: Int) -> Self { + public func clone(capacity: Int) -> Self { precondition(capacity >= count, "RigidArray capacity overflow") var result = RigidArray(capacity: capacity) let initialized = unsafe result._storage.initialize(fromContentsOf: _items) @@ -491,6 +491,29 @@ extension RigidArray { result._count = count return result } + + /// Copy the contents of this array into a newly allocated rigid array + /// instance with just enough capacity to hold all its elements. + /// + /// - Complexity: O(`count`) + @available(*, deprecated, renamed: "clone()") + @inlinable + public func copy() -> Self { + clone() + } + + /// Copy the contents of this array into a newly allocated rigid array + /// instance with the specified capacity. + /// + /// - Parameter capacity: The desired capacity of the resulting rigid array. + /// `capacity` must be greater than or equal to `count`. + /// + /// - Complexity: O(`count`) + @available(*, deprecated, renamed: "clone(capacity:)") + @inlinable + public func copy(capacity: Int) -> Self { + clone(capacity: capacity) + } } diff --git a/Sources/BasicContainers/UniqueArray/UniqueArray.swift b/Sources/BasicContainers/UniqueArray/UniqueArray.swift index fbd711d5..c1957e51 100644 --- a/Sources/BasicContainers/UniqueArray/UniqueArray.swift +++ b/Sources/BasicContainers/UniqueArray/UniqueArray.swift @@ -76,8 +76,8 @@ extension UniqueArray: Sendable where Element: Sendable & ~Copyable {} @available(SwiftStdlib 5.0, *) extension UniqueArray where Element: ~Copyable { - /// The maximum number of elements this array can hold without reallocating - /// its storage. + /// The maximum number of elements this array can hold without having to + /// reallocate its storage. /// /// - Complexity: O(1) @inlinable @@ -387,12 +387,11 @@ extension UniqueArray { /// instance with just enough capacity to hold all its elements. /// /// - Complexity: O(`count`) - @inlinable - @inline(__always) - public func copy() -> Self { - UniqueArray(consuming: _storage.copy()) + @_alwaysEmitIntoClient + public func clone() -> Self { + UniqueArray(consuming: _storage.clone()) } - + /// Copy the contents of this array into a newly allocated unique array /// instance with the specified capacity. /// @@ -402,8 +401,31 @@ extension UniqueArray { /// - Complexity: O(`count`) @inlinable @inline(__always) + public func clone(capacity: Int) -> Self { + UniqueArray(consuming: _storage.clone(capacity: capacity)) + } + + /// Copy the contents of this array into a newly allocated unique array + /// instance with just enough capacity to hold all its elements. + /// + /// - Complexity: O(`count`) + @available(*, deprecated, renamed: "clone()") + @inlinable + public func copy() -> Self { + self.clone() + } + + /// Copy the contents of this array into a newly allocated unique array + /// instance with the specified capacity. + /// + /// - Parameter capacity: The desired capacity of the resulting unique array. + /// `capacity` must be greater than or equal to `count`. + /// + /// - Complexity: O(`count`) + @available(*, deprecated, renamed: "clone(capacity:)") + @inlinable public func copy(capacity: Int) -> Self { - UniqueArray(consuming: _storage.copy(capacity: capacity)) + clone(capacity: capacity) } }