Similar to OrderedDictionary, we can forward our OrderedSet equality checks down to the ContiguousArray instance to take advantage of early return when both arrays point to the same identity (no need to perform a linear comparison over all elements).
A side-effect of this optimization is we also optimize OrderedDictionary.==, which performs an equality check on the keys property (which is an OrderedSet).[1]
Background
https://github.com/apple/swift-collections/pull/335
Similar to
OrderedDictionary
, we can forward ourOrderedSet
equality checks down to theContiguousArray
instance to take advantage of early return when both arrays point to the same identity (no need to perform a linear comparison over all elements).A side-effect of this optimization is we also optimize
OrderedDictionary.==
, which performs an equality check on thekeys
property (which is anOrderedSet
).[1][1] https://github.com/apple/swift-collections/blob/main/Sources/OrderedCollections/OrderedDictionary/OrderedDictionary%2BEquatable.swift#L20-L22
Changes
From:
To:
We can also migrate
OrderedSet.SubSequence
. From:To:
Test Plan
Five new tests are added:
OrderedSetTests.test_equal
OrderedSetTests.test_not_equal
OrderedSetTests.test_equal_elements
OrderedSetTests.test_subsequence_equality
OrderedSetTests.test_subsequence_not_equality
Checklist