Skip to content

Commit

Permalink
[stdlib] Make dictionary.keys.contains(key) O(1) even when wrapping a…
Browse files Browse the repository at this point in the history
… NSDictionary
  • Loading branch information
koher committed May 2, 2018
1 parent 903f55b commit 2da85ec
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion stdlib/public/core/Dictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ extension Dictionary {

@inlinable // FIXME(sil-serialize-all)
public func _customContainsEquatableElement(_ element: Element) -> Bool? {
return _variantBuffer.index(forKey: element) != nil
return _variantBuffer.containsKey(element)
}

@inlinable // FIXME(sil-serialize-all)
Expand Down Expand Up @@ -3419,6 +3419,23 @@ internal enum _VariantDictionaryBuffer<Key: Hashable, Value>: _HashBuffer {
}
}

@inlinable // FIXME(sil-serialize-all)
@inline(__always)
internal func containsKey(_ key: Key) -> Bool {
if _fastPath(guaranteedNative) {
return asNative.index(forKey: key) != nil
}

switch self {
case .native:
return asNative.index(forKey: key) != nil
#if _runtime(_ObjC)
case .cocoa(let cocoaBuffer):
return SelfType.maybeGetFromCocoaBuffer(cocoaBuffer, forKey: key) != nil
#endif
}
}

@inlinable // FIXME(sil-serialize-all)
internal func assertingGet(_ i: Index) -> SequenceElement {
if _fastPath(guaranteedNative) {
Expand Down

0 comments on commit 2da85ec

Please sign in to comment.