Skip to content

Commit 84d8ced

Browse files
committed
[stdlib] _SetBuilder, _DictionaryBuilder: Assume target has enough capacity
The compiled code included unnecessary references to resize().
1 parent be0abbb commit 84d8ced

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

stdlib/public/core/DictionaryBuilder.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ struct _DictionaryBuilder<Key: Hashable, Value> {
3030

3131
@inlinable
3232
public mutating func add(key newKey: Key, value: Value) {
33-
_target.insertNew(key: newKey, value: value)
33+
_precondition(_target.count < _requestedCount,
34+
"Can't add more members than promised")
35+
_target._unsafeInsertNew(key: newKey, value: value)
3436
}
3537

3638
@inlinable

stdlib/public/core/SetBuilder.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ struct _SetBuilder<Element: Hashable> {
2929
}
3030

3131
@inlinable
32+
@inline(__always)
3233
public mutating func add(member: Element) {
3334
_precondition(_target.count < _requestedCount,
3435
"Can't add more members than promised")
35-
_target.insertNew(member, isUnique: true)
36+
_target._unsafeInsertNew(member)
3637
}
3738

3839
@inlinable

0 commit comments

Comments
 (0)