Skip to content

Commit 9c28ff0

Browse files
committed
compare Set and Dictionary by address for equality
as noted in the comment, the native storage version of Set and Dictionary can be considered equal if their Owner object have the same address. This should speed up == by quite a bit in those cases. use === for equality of HashedCollection owner
1 parent e29398d commit 9c28ff0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

stdlib/public/core/HashedCollections.swift.gyb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,10 @@ public func == <Element : Hashable>(lhs: Set<Element>, rhs: Set<Element>) -> Boo
678678
case (.Native(let lhsNativeOwner), .Native(let rhsNativeOwner)):
679679
let lhsNative = lhsNativeOwner.nativeStorage
680680
let rhsNative = rhsNativeOwner.nativeStorage
681-
// FIXME(performance): early exit if lhs and rhs reference the same
682-
// storage?
681+
682+
if lhsNativeOwner === rhsNativeOwner {
683+
return true
684+
}
683685

684686
if lhsNative.count != rhsNative.count {
685687
return false
@@ -1184,8 +1186,10 @@ public func == <Key : Equatable, Value : Equatable>(
11841186
case (.Native(let lhsNativeOwner), .Native(let rhsNativeOwner)):
11851187
let lhsNative = lhsNativeOwner.nativeStorage
11861188
let rhsNative = rhsNativeOwner.nativeStorage
1187-
// FIXME(performance): early exit if lhs and rhs reference the same
1188-
// storage?
1189+
1190+
if lhsNativeOwner === rhsNativeOwner {
1191+
return true
1192+
}
11891193

11901194
if lhsNative.count != rhsNative.count {
11911195
return false

0 commit comments

Comments
 (0)