Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Sources/SkipLib/Collections.swift
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,6 @@ extension RangeReplaceableCollection {
public mutating func replaceSubrange(_ subrange: any RangeExpression<Int>, with newElements: any Collection<Element>) {
}

@available(*, unavailable)
public mutating func reserveCapacity(_ n: Int) {
}

Expand Down
7 changes: 7 additions & 0 deletions Sources/SkipLib/Skip/Array.kt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ class Array<Element>: RandomAccessCollection<Element>, RangeReplaceableCollectio
}
}

fun reserveCapacity(n: Int) {
val mlist = mutableList
if (mlist is ArrayList) {
mlist.ensureCapacity(n)
}
}

companion object {
}
}
5 changes: 5 additions & 0 deletions Tests/SkipLibTests/CollectionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ final class CollectionsTests: XCTestCase {
XCTAssertEqual(0, arr.count)
XCTAssertTrue(arr.isEmpty)
}

func testReserveCapacity() {
var arr = [1, 3, 5]
arr.reserveCapacity(100)
}
}

private enum ElementEnum: Int, CaseIterable {
Expand Down