Skip to content

Commit

Permalink
Merge pull request apple#113 from lorentey/deque-scaling
Browse files Browse the repository at this point in the history
[Deque] `append(contentsOf:):` Use exponential capacity reservation
  • Loading branch information
lorentey authored Nov 16, 2021
2 parents 1337897 + efefae5 commit 4825482
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/DequeModule/Deque+Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ extension Deque: RangeReplaceableCollection {
}

let underestimatedCount = newElements.underestimatedCount
reserveCapacity(count + underestimatedCount)
_storage.ensureUnique(minimumCapacity: count + underestimatedCount)
var it: S.Iterator = _storage.update { target in
let gaps = target.availableSegments()
let (it, copied) = gaps.initialize(fromSequencePrefix: newElements)
Expand Down Expand Up @@ -713,7 +713,7 @@ extension Deque: RangeReplaceableCollection {

let c = newElements.count
guard c > 0 else { return }
reserveCapacity(count + c)
_storage.ensureUnique(minimumCapacity: count + c)
_storage.update { target in
let gaps = target.availableSegments().prefix(c)
gaps.initialize(from: newElements)
Expand Down

0 comments on commit 4825482

Please sign in to comment.