Skip to content

Commit 7f330ed

Browse files
Merge pull request swiftlang#298 from ktopley-apple/dispatch-time-resync
Synchronize the Linux and Darwin overlay versions of Time.swift
2 parents 9ec74ed + 4824544 commit 7f330ed

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/swift/Time.swift

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -78,13 +78,14 @@ public struct DispatchTime : Comparable {
7878
}
7979
}
8080

81-
public func <(a: DispatchTime, b: DispatchTime) -> Bool {
82-
if a.rawValue == ~0 || b.rawValue == ~0 { return false }
83-
return a.rawValue < b.rawValue
84-
}
81+
extension DispatchTime {
82+
public static func < (a: DispatchTime, b: DispatchTime) -> Bool {
83+
return a.rawValue < b.rawValue
84+
}
8585

86-
public func ==(a: DispatchTime, b: DispatchTime) -> Bool {
87-
return a.rawValue == b.rawValue
86+
public static func ==(a: DispatchTime, b: DispatchTime) -> Bool {
87+
return a.rawValue == b.rawValue
88+
}
8889
}
8990

9091
public struct DispatchWallTime : Comparable {
@@ -106,17 +107,20 @@ public struct DispatchWallTime : Comparable {
106107
}
107108
}
108109

109-
public func <(a: DispatchWallTime, b: DispatchWallTime) -> Bool {
110-
if b.rawValue == ~0 {
111-
return a.rawValue != ~0
112-
} else if a.rawValue == ~0 {
113-
return false
110+
extension DispatchWallTime {
111+
public static func <(a: DispatchWallTime, b: DispatchWallTime) -> Bool {
112+
let negativeOne: dispatch_time_t = ~0
113+
if b.rawValue == negativeOne {
114+
return a.rawValue != negativeOne
115+
} else if a.rawValue == negativeOne {
116+
return false
117+
}
118+
return -Int64(bitPattern: a.rawValue) < -Int64(bitPattern: b.rawValue)
114119
}
115-
return -Int64(bitPattern: a.rawValue) < -Int64(bitPattern: b.rawValue)
116-
}
117120

118-
public func ==(a: DispatchWallTime, b: DispatchWallTime) -> Bool {
119-
return a.rawValue == b.rawValue
121+
public static func ==(a: DispatchWallTime, b: DispatchWallTime) -> Bool {
122+
return a.rawValue == b.rawValue
123+
}
120124
}
121125

122126
public enum DispatchTimeInterval {

0 commit comments

Comments
 (0)