Skip to content

Commit 76b5afc

Browse files
author
Dave Abrahams
committed
Speed up Set/Dictionary init from Sequence
Alternative to #5264
1 parent 222811a commit 76b5afc

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

stdlib/public/core/HashedCollections.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ public struct Set<Element : Hashable> :
762762
/// - Parameter sequence: The elements to use as members of the new set.
763763
public init<Source : Sequence>(_ sequence: Source)
764764
where Source.Iterator.Element == Element {
765-
self.init()
765+
self.init(minimumCapacity: sequence.underestimatedCount)
766766
if let s = sequence as? Set<Element> {
767767
// If this sequence is actually a native `Set`, then we can quickly
768768
// adopt its native storage and let COW handle uniquing only

0 commit comments

Comments
 (0)