Why do decodable collections in stdlib not reserve capacity?

I was reading some of the internal implementations in the stdlib and noticed that none of the decodable collections in stdlib reserve capacity before appending decoded elements.

https://github.com/apple/swift/blob/master/stdlib/public/core/Codable.swift.gyb#L1752-L1768

https://github.com/apple/swift/blob/master/stdlib/public/core/Codable.swift.gyb#L1786-L1802

https://github.com/apple/swift/blob/master/stdlib/public/core/Codable.swift.gyb#L1820-L1852

https://github.com/apple/swift/blob/master/stdlib/public/core/Codable.swift.gyb#L1893

Do I miss something or why wouldn't we just include this line everywhere?

container.count.map(reserveCapacity)
4 Likes

From my end, there’s no reason for this beyond oversight — I think we can just do it in a bug fix if someone is willing to file a JIRA and put up a PR :slight_smile:

3 Likes

Okay, then I'll do it tomorrow.

3 Likes