[OrderedCollections] Use exchange(_:with:) in replaceElement's equal-key path

#688 factored `replaceElement`'s general case onto `OrderedSet._replaceNew(at:with:in:)` and, per review feedback, switched the value overwrite there to `exchange(_:with:)`. The equal-key path above it was outside that diff, so it still reads the old value into a local and then assigns over it.

Switch it to `exchange(_:with:)` as well, so both paths move the old value out instead of copying it. No behavior change: the returned element, the preconditions, and the expected amortized O(1) complexity are all unchanged.
This commit is contained in:
inju2403 committed 2026-08-14 09:19:43 +09:00
1 parent f3e778f17a
commit 7a67033ee2
1 file changed
+1 -2
@@ -83,8 +83,7 @@ extension OrderedDictionary {
// in place. The hash bucket is unchanged, so no rehash is needed.
if existingIndex == index {
let oldKey = _keys.update(key, at: index)
let oldValue = _values[index]
_values[index] = value
let oldValue = exchange(&_values[index], with: value)
_checkInvariants()
return (oldKey, oldValue)
}