Skip to content

Commit

Permalink
[stdlib] Handle some outstanding Dictionary indexing-model FIXMEs/TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis Beingessner committed Oct 29, 2016
1 parent b08732c commit 953e51a
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions stdlib/public/core/HashedCollections.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,10 @@ public struct Set<Element : Hashable> :
return _variantStorage.endIndex
}

// TODO: swift-3-indexing-model - add docs
/// Returns the index after the given one.
///
/// If this is the last valid index, returns endIndex.
/// Aborts on endIndex.
public func index(after i: Index) -> Index {
return _variantStorage.index(after: i)
}
Expand Down Expand Up @@ -1662,7 +1665,10 @@ public struct Dictionary<Key : Hashable, Value> :
return _variantStorage.endIndex
}

// TODO: swift-3-indexing-model - add docs
/// Returns the index after the given one.
///
/// If this is the last valid index, returns endIndex.
/// Aborts on endIndex.
public func index(after i: Index) -> Index {
return _variantStorage.index(after: i)
}
Expand Down Expand Up @@ -2063,15 +2069,15 @@ extension Dictionary where Key : Equatable, Value : Equatable {
let (key, value) = lhsNative.assertingGet(index)
let optRhsValue: AnyObject? =
rhsCocoa.maybeGet(_bridgeAnythingToObjectiveC(key))
// TODO: swift-3-indexing-model: change 'if' into 'guard'.
if let rhsValue = optRhsValue {
if value == _forceBridgeFromObjectiveC(rhsValue, Value.self) {
lhsNative.formIndex(after: &index)
continue
}

guard let rhsValue = optRhsValue,
value == _forceBridgeFromObjectiveC(rhsValue, Value.self)
else {
return false
}
index = lhsNative.index(after: index)
return false

lhsNative.formIndex(after: &index)
continue
}
return true
#else
Expand Down Expand Up @@ -4321,6 +4327,10 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorage {
}
}

%{
compareOperators = ["<", "<=", ">", ">=", "=="]
}%

@_versioned
internal struct _Native${Self}Index<${TypeParametersDecl}> : Comparable {
@_versioned
Expand All @@ -4333,24 +4343,19 @@ internal struct _Native${Self}Index<${TypeParametersDecl}> : Comparable {
}

extension _Native${Self}Index {
internal static func == (
lhs: _Native${Self}Index<${TypeParameters}>,
rhs: _Native${Self}Index<${TypeParameters}>
) -> Bool {
// FIXME: assert that lhs and rhs are from the same dictionary.
return lhs.offset == rhs.offset
}

internal static func < (
% for op in compareOperators:
internal static func ${op} (
lhs: _Native${Self}Index<${TypeParameters}>,
rhs: _Native${Self}Index<${TypeParameters}>
) -> Bool {
// FIXME: assert that lhs and rhs are from the same dictionary.
return lhs.offset < rhs.offset
return lhs.offset ${op} rhs.offset
}
// TODO: swift-3-indexing-model: forward all Comparable operations.
% end

}


#if _runtime(_ObjC)
@_versioned
internal struct _Cocoa${Self}Index : Comparable {
Expand All @@ -4363,19 +4368,16 @@ internal struct _Cocoa${Self}Index : Comparable {
}

extension _Cocoa${Self}Index {
internal static func == (
lhs: _Cocoa${Self}Index,
rhs: _Cocoa${Self}Index
) -> Bool {
return lhs.currentKeyIndex == rhs.currentKeyIndex
}

internal static func < (
% for op in compareOperators:
internal static func ${op} (
lhs: _Cocoa${Self}Index,
rhs: _Cocoa${Self}Index
) -> Bool {
return lhs.currentKeyIndex < rhs.currentKeyIndex
return lhs.currentKeyIndex ${op} rhs.currentKeyIndex
}
% end

}
#else
internal struct _Cocoa${Self}Index {}
Expand Down Expand Up @@ -4413,9 +4415,8 @@ elif Self == 'Dictionary':
${SubscriptingWithIndexDoc}
public struct ${Self}Index<${TypeParametersDecl}> :
Comparable {
// FIXME(swift-3-indexing-model): rewrite the fixme to reflect the new index model
// FIXME(ABI)#34 (Nesting types in generics): `DictionaryIndex` and `SetIndex` should
// be nested types.
// be nested types (Dictionary.Index and Set.Index).
// rdar://problem/17002096

// Index for native storage is efficient. Index for bridged NS${Self} is
Expand Down

0 comments on commit 953e51a

Please sign in to comment.