Skip to content

Commit 41d8b2f

Browse files
authored
Merge pull request #6211 from dtorres/unique-removeAll
[stdlib] Resolve unnecessary buffer copy in HashedCollections
2 parents a91af1f + 7168a9e commit 41d8b2f

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

stdlib/public/core/HashedCollections.swift.gyb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4482,14 +4482,13 @@ internal enum _Variant${Self}Buffer<${TypeParametersDecl}> : _HashBuffer {
44824482
}
44834483

44844484
internal mutating func nativeRemoveAll() {
4485-
// FIXME(performance): if the buffer is non-uniquely referenced, we
4486-
// shouldn't be copying the elements into new buffer and then immediately
4487-
// deleting the elements. We should detect that the buffer is not uniquely
4488-
// referenced and allocate new empty buffer of appropriate capacity.
4485+
if !isUniquelyReferenced() {
4486+
asNative = NativeBuffer(minimumCapacity: asNative.capacity)
4487+
return
4488+
}
44894489

4490-
// We have already checked for the empty dictionary case, so we will always
4491-
// mutating the dictionary buffer. Request unique buffer.
4492-
_ = ensureUniqueNativeBuffer(asNative.capacity)
4490+
// We have already checked for the empty dictionary case and unique
4491+
// reference, so we will always mutate the dictionary buffer.
44934492
var nativeBuffer = asNative
44944493

44954494
for b in 0..<nativeBuffer.capacity {

0 commit comments

Comments
 (0)