Skip to content

Commit a5c13be

Browse files
committed
More precise tuple comparison in Timestamp
1 parent bf8c689 commit a5c13be

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

lib/bson/timestamp.rb

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,10 @@ def ==(other)
7070
# @since 4.3.0
7171
def <=>(other)
7272
raise ArgumentError.new(COMPARISON_ERROR_MESSAGE % other.class) unless other.is_a?(Timestamp)
73-
time = seconds + increment
74-
other_time = other.seconds + other.increment
75-
if time < other_time
76-
-1
77-
elsif time > other_time
78-
1
79-
else
80-
0
81-
end
73+
return 0 if self == other
74+
a = [ seconds, increment ]
75+
b = [ other.seconds, other.increment ]
76+
[ a, b ].sort[0] == a ? -1 : 1
8277
end
8378

8479
# Get the timestamp as JSON hash data.

0 commit comments

Comments
 (0)