Skip to content

Provide a way to optimize allocation amounts in Unique/RigidArray #555

@MahdiBM

Description

@MahdiBM

When asking for reserving capacity, Swift's Array takes it as "minimum capacity" that it should reserve.
Unique/RigidArray though, take it very literally and only allocate those exact amounts:

import BasicContainers

var uniq = UniqueArray<UInt8>(capacity: 10)
var arr = Array<UInt8>()
arr.reserveCapacity(10)

print(uniq.capacity) /// prints 10
print(arr.capacity) /// prints 16

I think It's likely better to just copy paste the algorithm that Array uses for reserving capacities?
Or there could be new functions / initializers for this purpose.

I just recently moved swift-idna to use Unique/RigidArray instead of Array, and noticed this behavior.

@lorentey WDYT? I could do the PRs if this sounds like a good idea to you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions