From 1e310e2908c535c78b0e78ceb82bbb3193d65947 Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Tue, 3 Feb 2026 13:20:48 -0800 Subject: [PATCH] =?UTF-8?q?[BasicContainers]=20RigidArray,=20UniqueArray:?= =?UTF-8?q?=20Rename=20copy()=20=E2=86=92=20clone()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RigidArray/RigidArray.swift | 33 +++++++++++++--- .../UniqueArray/UniqueArray.swift | 38 +++++++++++++++---- 2 files changed, 58 insertions(+), 13 deletions(-) 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) } }