@@ -258,7 +258,7 @@ extension Set: Sequence {
258
258
/// - Complexity: O(1)
259
259
@inlinable
260
260
public func contains( _ member: Element ) -> Bool {
261
- return _variant. maybeGet ( member) != nil
261
+ return _variant. contains ( member)
262
262
}
263
263
264
264
@inlinable
@@ -1499,6 +1499,7 @@ internal protocol _SetBuffer { // FIXME: Remove or refactor for Set.
1499
1499
func index( forKey key: Element ) -> Index ?
1500
1500
var count : Int { get }
1501
1501
1502
+ func contains( _ member: Element ) -> Bool
1502
1503
func assertingGet( at i: Index ) -> Element
1503
1504
func maybeGet( _ key: Element ) -> Element ?
1504
1505
}
@@ -2235,6 +2236,16 @@ extension _NativeSet/*: _SetBuffer*/ where Element: Hashable {
2235
2236
return found ? i : nil
2236
2237
}
2237
2238
2239
+ @inlinable
2240
+ @inline ( __always)
2241
+ internal func contains( _ member: Element ) -> Bool {
2242
+ if count == 0 {
2243
+ // Fast path that avoids computing the hash of the key.
2244
+ return false
2245
+ }
2246
+ return _find ( member) . found
2247
+ }
2248
+
2238
2249
@inlinable // FIXME(sil-serialize-all)
2239
2250
@inline ( __always)
2240
2251
internal func maybeGet( _ key: Element ) -> Element ? {
@@ -2560,6 +2571,11 @@ internal struct _CocoaSet: _SetBuffer {
2560
2571
return object. count
2561
2572
}
2562
2573
2574
+ @inlinable
2575
+ internal func contains( _ element: AnyObject ) -> Bool {
2576
+ return object. member ( element) != nil
2577
+ }
2578
+
2563
2579
@inlinable // FIXME(sil-serialize-all)
2564
2580
internal func assertingGet( at i: Index ) -> AnyObject {
2565
2581
let value : AnyObject ? = i. allKeys [ i. currentKeyIndex]
@@ -2890,6 +2906,23 @@ extension Set._Variant: _SetBuffer {
2890
2906
}
2891
2907
}
2892
2908
2909
+ @inlinable
2910
+ @inline ( __always)
2911
+ internal func contains( _ member: Element ) -> Bool {
2912
+ if _fastPath ( guaranteedNative) {
2913
+ return asNative. contains ( member)
2914
+ }
2915
+ switch self {
2916
+ case . native( let native) :
2917
+ return native. contains ( member)
2918
+ #if _runtime(_ObjC)
2919
+ case . cocoa( let cocoa) :
2920
+ let cocoaKey = _bridgeAnythingToObjectiveC ( member)
2921
+ return cocoa. contains ( cocoaKey)
2922
+ #endif
2923
+ }
2924
+ }
2925
+
2893
2926
#if _runtime(_ObjC)
2894
2927
@inline ( never)
2895
2928
@usableFromInline
0 commit comments