Skip to content

Commit 22d5acd

Browse files
committed
Fix logic around comparison
1 parent d680396 commit 22d5acd

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

stdlib/public/Synchronization/Atomics/WordPair.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,11 @@ extension WordPair: Comparable {
191191
@_alwaysEmitIntoClient
192192
@_transparent
193193
public func <(lhs: WordPair, rhs: WordPair) -> Bool {
194-
lhs.first < rhs.first || lhs.second < rhs.second
194+
if lhs.first != rhs.first {
195+
return lhs.first < rhs.first
196+
} else {
197+
return lhs.second < rhs.second
198+
}
195199
}
196200
}
197201

test/stdlib/Synchronization/Atomics/WordPair.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,15 @@ suite.test("basics") {
5050
let c1 = WordPair(first: 1, second: 0)
5151
let c2 = WordPair(first: 2, second: 0)
5252
let c3 = WordPair(first: 0, second: 1)
53+
let c4 = WordPair(first: 1, second: 2)
54+
let c5 = WordPair(first: 2, second: 1)
5355
expectFalse(c0 < c0)
5456
expectTrue(c0 < c1)
5557
expectTrue(c0 < c2)
5658
expectTrue(c0 < c3)
5759
expectFalse(c1 < c0)
60+
expectTrue(c4 < c5)
61+
expectFalse(c5 < c4)
5862
}
5963

6064
} // if #available(SwiftStdlib 6.0, *)

0 commit comments

Comments
 (0)