Skip to content

Commit 1529d37

Browse files
committed
[stdlib] Implement formIndex(after:) in all hashed collections
1 parent 526162f commit 1529d37

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

stdlib/public/core/Dictionary.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,11 @@ extension Dictionary: Collection {
647647
return _variant.index(after: i)
648648
}
649649

650+
@inlinable
651+
public func formIndex(after i: inout Index) {
652+
_variant.formIndex(after: &i)
653+
}
654+
650655
/// Returns the index for the given key.
651656
///
652657
/// If the given key is found in the dictionary, this method returns an index
@@ -1350,6 +1355,11 @@ extension Dictionary {
13501355
return _variant.index(after: i)
13511356
}
13521357

1358+
@inlinable
1359+
public func formIndex(after i: inout Index) {
1360+
_variant.formIndex(after: &i)
1361+
}
1362+
13531363
@inlinable
13541364
public subscript(position: Index) -> Element {
13551365
return _variant.key(at: position)
@@ -1456,6 +1466,11 @@ extension Dictionary {
14561466
return _variant.index(after: i)
14571467
}
14581468

1469+
@inlinable
1470+
public func formIndex(after i: inout Index) {
1471+
_variant.formIndex(after: &i)
1472+
}
1473+
14591474
@inlinable
14601475
public subscript(position: Index) -> Element {
14611476
// FIXME(accessors): Provide a _read

stdlib/public/core/DictionaryVariant.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,20 @@ extension Dictionary._Variant: _DictionaryBuffer {
189189
}
190190
}
191191

192+
@inlinable
193+
internal func formIndex(after index: inout Index) {
194+
switch self {
195+
case .native(let native):
196+
index = native.index(after: index)
197+
#if _runtime(_ObjC)
198+
case .cocoa(let cocoa):
199+
cocoaPath()
200+
let isUnique = index._isUniquelyReferenced()
201+
cocoa.formIndex(after: &index._asCocoa, isUnique: isUnique)
202+
#endif
203+
}
204+
}
205+
192206
@inlinable
193207
@inline(__always)
194208
internal func index(forKey key: Key) -> Index? {

stdlib/public/core/Set.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,11 @@ extension Set: Collection {
340340
return _variant.index(after: i)
341341
}
342342

343+
@inlinable
344+
public func formIndex(after i: inout Index) {
345+
_variant.formIndex(after: &i)
346+
}
347+
343348
// APINAMING: complexity docs are broadly missing in this file.
344349

345350
/// Returns the index of the given element in the set, or `nil` if the

stdlib/public/core/SetVariant.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,20 @@ extension Set._Variant: _SetBuffer {
182182
}
183183
}
184184

185+
@inlinable
186+
internal func formIndex(after index: inout Index) {
187+
switch self {
188+
case .native(let native):
189+
index = native.index(after: index)
190+
#if _runtime(_ObjC)
191+
case .cocoa(let cocoa):
192+
cocoaPath()
193+
let isUnique = index._isUniquelyReferenced()
194+
cocoa.formIndex(after: &index._asCocoa, isUnique: isUnique)
195+
#endif
196+
}
197+
}
198+
185199
@inlinable
186200
@inline(__always)
187201
internal func index(for element: Element) -> Index? {

0 commit comments

Comments
 (0)