Skip to content

[BasicContainers] Rename reallocate to setCapacity for Rigid and UniqueArray#667

Open
Azoy wants to merge 1 commit into
apple:mainfrom
Azoy:setcapacity
Open

[BasicContainers] Rename reallocate to setCapacity for Rigid and UniqueArray#667
Azoy wants to merge 1 commit into
apple:mainfrom
Azoy:setcapacity

Conversation

@Azoy

@Azoy Azoy commented Jun 10, 2026

Copy link
Copy Markdown
Member

Based on the accepted name of this function in the recent standard library proposal, rename reallocate here to setCapacity as well deprecating the old name.

Checklist

  • I've read the Contribution Guidelines
  • My contributions are licensed under the Swift license.
  • I've followed the coding style of the rest of the project.
  • I've added tests covering all new code paths my change adds to the project (if appropriate).
  • I've added benchmarks covering new functionality (if appropriate).
  • I've verified that my change does not break any existing tests or introduce unexplained benchmark regressions.
  • I've updated the documentation if necessary.

@Azoy Azoy requested a review from lorentey as a code owner June 10, 2026 17:32
Update UniqueArray.swift

Update UniqueArray.swift

@lorentey lorentey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 with the changes noted!

Comment on lines +95 to +102
precondition(newCapacity >= count, "RigidArray capacity overflow")
guard newCapacity != capacity else { return }
let newStorage: UnsafeMutableBufferPointer<Element> = .allocate(
capacity: newCapacity)
let i = unsafe newStorage.moveInitialize(fromContentsOf: self._items)
assert(i == count)
unsafe _storage.deallocate()
unsafe _storage = newStorage

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
precondition(newCapacity >= count, "RigidArray capacity overflow")
guard newCapacity != capacity else { return }
let newStorage: UnsafeMutableBufferPointer<Element> = .allocate(
capacity: newCapacity)
let i = unsafe newStorage.moveInitialize(fromContentsOf: self._items)
assert(i == count)
unsafe _storage.deallocate()
unsafe _storage = newStorage
setCapacity(newCapacity)

Comment on lines 347 to 348
/// - Parameter newCapacity: The desired new capacity. `newCapacity` must be
/// greater than or equal to the current count.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// - Parameter newCapacity: The desired new capacity. The new capacity
/// is set to the maximum of `newCapacity` and the current count.

Comment on lines 257 to 258
/// - Parameter newCapacity: The desired new capacity. `newCapacity` must be
/// greater than or equal to the current count.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// - Parameter newCapacity: The desired new capacity. The new capacity
/// is set to the maximum of `newCapacity` and the current count.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants