Skip to content

Commit

Permalink
[OrderedDictionary] Deprecate subscript(offset:) for now (apple#92)
Browse files Browse the repository at this point in the history
* [OrderedDictionary] Deprecate index(forKey:), subscript(offset:) and friends for now

* [OrderedDictionary] Update tests

* Update benchmarks

* Un-deprecate index(forKey:)
  • Loading branch information
lorentey committed Aug 20, 2021
1 parent e7e7751 commit 8ef7b77
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 361 deletions.
14 changes: 14 additions & 0 deletions Sources/CollectionsTestSupport/AssertionContexts/Assertions.swift
Expand Up @@ -188,6 +188,20 @@ public func expectEqual<T: Equatable>(
message, trapping: trapping, file: file, line: line)
}

public func expectEqual<Key: Equatable, Value: Equatable>(
_ left: (key: Key, value: Value), _ right: (key: Key, value: Value),
_ message: @autoclosure () -> String = "",
trapping: Bool = false,
file: StaticString = #file,
line: UInt = #line
) {
if left == right { return }
_expectFailure(
"'\(left)' is not equal to '\(right)'",
message, trapping: trapping, file: file, line: line)
}


public func expectEqual<T: Equatable>(
_ left: T?, _ right: T?,
_ message: @autoclosure () -> String = "",
Expand Down
Expand Up @@ -10,7 +10,27 @@
//===----------------------------------------------------------------------===//

extension OrderedDictionary {
@available(*, deprecated, renamed: "updateValue(forKey:default:with:)")
/// Accesses the element at the specified index. This can be used to
/// perform in-place mutations on dictionary values.
///
/// - Parameter offset: The offset of the element to access, measured from
/// the start of the collection. `offset` must be greater than or equal to
/// `0` and less than `count`.
///
/// - Complexity: O(1)
@available(*, deprecated, // since 0.0.6
message: "Please use `elements[offset]`")
@inlinable
@inline(__always)
public subscript(offset offset: Int) -> Element {
(_keys[offset], _values[offset])
}
}

extension OrderedDictionary {
// Deprecated since 0.0.6
@available(*, deprecated, // since 0.0.6
renamed: "updateValue(forKey:default:with:)")
@inlinable
public mutating func modifyValue<R>(
forKey key: Key,
Expand All @@ -20,7 +40,8 @@ extension OrderedDictionary {
try self.updateValue(forKey: key, default: defaultValue(), with: body)
}

@available(*, deprecated, renamed: "updateValue(forKey:insertingDefault:at:with:)")
@available(*, deprecated, // since 0.0.6
renamed: "updateValue(forKey:insertingDefault:at:with:)")
@inlinable
public mutating func modifyValue<R>(
forKey key: Key,
Expand Down
Expand Up @@ -290,7 +290,7 @@ extension OrderedDictionary.Elements.SubSequence: RandomAccessCollection {
@inlinable
public subscript(position: Int) -> Element {
precondition(_bounds.contains(position), "Index out of range")
return _base[offset: position]
return (_base._keys[position], _base._values[position])
}

/// Accesses a contiguous subrange of the dictionary's elements.
Expand Down
Expand Up @@ -287,20 +287,6 @@ extension OrderedDictionary {
public func index(forKey key: Key) -> Int? {
_keys.firstIndex(of: key)
}

/// Accesses the element at the specified index. This can be used to
/// perform in-place mutations on dictionary values.
///
/// - Parameter offset: The offset of the element to access, measured from
/// the start of the collection. `offset` must be greater than or equal to
/// `0` and less than `count`.
///
/// - Complexity: O(1)
@inlinable
@inline(__always)
public subscript(offset offset: Int) -> Element {
(_keys[offset], _values[offset])
}
}

extension OrderedDictionary {
Expand Down

0 comments on commit 8ef7b77

Please sign in to comment.