Skip to content

Commit cc48aa4

Browse files
authored
Merge pull request #15151 from ikesyo/stdlib-public-operator-static-func
[SE-0091][gardening][stdlib/public] Move operators into types
2 parents c5dcf01 + 1fbc030 commit cc48aa4

File tree

6 files changed

+66
-64
lines changed

6 files changed

+66
-64
lines changed

stdlib/public/Platform/Platform.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ extension DarwinBoolean : CustomStringConvertible {
5757
}
5858
}
5959

60-
extension DarwinBoolean : Equatable {}
61-
public func ==(lhs: DarwinBoolean, rhs: DarwinBoolean) -> Bool {
62-
return lhs.boolValue == rhs.boolValue
60+
extension DarwinBoolean : Equatable {
61+
public static func ==(lhs: DarwinBoolean, rhs: DarwinBoolean) -> Bool {
62+
return lhs.boolValue == rhs.boolValue
63+
}
6364
}
6465

6566
public // COMPILER_INTRINSIC

stdlib/public/SDK/CoreMedia/CMTime.swift

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -99,34 +99,36 @@ public func CMTIME_HAS_BEEN_ROUNDED(_ time: CMTime) -> Bool {
9999
return time.hasBeenRounded
100100
}
101101

102-
// CMTimeAdd
103-
public func + (addend1: CMTime, addend2: CMTime) -> CMTime {
104-
return CMTimeAdd(addend1, addend2)
105-
}
106-
107-
// CMTimeSubtract
108-
public func - (minuend: CMTime, subtrahend: CMTime) -> CMTime {
109-
return CMTimeSubtract(minuend, subtrahend)
102+
extension CMTime {
103+
// CMTimeAdd
104+
public static func + (addend1: CMTime, addend2: CMTime) -> CMTime {
105+
return CMTimeAdd(addend1, addend2)
106+
}
107+
108+
// CMTimeSubtract
109+
public static func - (minuend: CMTime, subtrahend: CMTime) -> CMTime {
110+
return CMTimeSubtract(minuend, subtrahend)
111+
}
110112
}
111113

112-
extension CMTime : Equatable, Comparable {}
113-
114114
// CMTimeCompare
115-
public func < (time1: CMTime, time2: CMTime) -> Bool {
116-
return CMTimeCompare(time1, time2) < 0
117-
}
118-
public func <= (time1: CMTime, time2: CMTime) -> Bool {
119-
return CMTimeCompare(time1, time2) <= 0
120-
}
121-
public func > (time1: CMTime, time2: CMTime) -> Bool {
122-
return CMTimeCompare(time1, time2) > 0
123-
}
124-
public func >= (time1: CMTime, time2: CMTime) -> Bool {
125-
return CMTimeCompare(time1, time2) >= 0
126-
}
127-
public func == (time1: CMTime, time2: CMTime) -> Bool {
128-
return CMTimeCompare(time1, time2) == 0
129-
}
130-
public func != (time1: CMTime, time2: CMTime) -> Bool {
131-
return CMTimeCompare(time1, time2) != 0
115+
extension CMTime : Equatable, Comparable {
116+
public static func < (time1: CMTime, time2: CMTime) -> Bool {
117+
return CMTimeCompare(time1, time2) < 0
118+
}
119+
public static func <= (time1: CMTime, time2: CMTime) -> Bool {
120+
return CMTimeCompare(time1, time2) <= 0
121+
}
122+
public static func > (time1: CMTime, time2: CMTime) -> Bool {
123+
return CMTimeCompare(time1, time2) > 0
124+
}
125+
public static func >= (time1: CMTime, time2: CMTime) -> Bool {
126+
return CMTimeCompare(time1, time2) >= 0
127+
}
128+
public static func == (time1: CMTime, time2: CMTime) -> Bool {
129+
return CMTimeCompare(time1, time2) == 0
130+
}
131+
public static func != (time1: CMTime, time2: CMTime) -> Bool {
132+
return CMTimeCompare(time1, time2) != 0
133+
}
132134
}

stdlib/public/SDK/CoreMedia/CMTimeRange.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,13 @@ public func CMTIMERANGE_IS_EMPTY (_ range: CMTimeRange) -> Bool {
7474
return range.isEmpty
7575
}
7676

77-
extension CMTimeRange : Equatable {}
78-
7977
// CMTimeRangeEqual
80-
public func == (range1: CMTimeRange, range2: CMTimeRange) -> Bool {
81-
return CMTimeRangeEqual(range1, range2)
82-
}
83-
84-
public func != (range1: CMTimeRange, range2: CMTimeRange) -> Bool {
85-
return !CMTimeRangeEqual(range1, range2)
78+
extension CMTimeRange : Equatable {
79+
public static func == (range1: CMTimeRange, range2: CMTimeRange) -> Bool {
80+
return CMTimeRangeEqual(range1, range2)
81+
}
82+
83+
public static func != (range1: CMTimeRange, range2: CMTimeRange) -> Bool {
84+
return !CMTimeRangeEqual(range1, range2)
85+
}
8686
}
87-

stdlib/public/SDK/Dispatch/Dispatch.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ public struct DispatchQoS : Equatable {
114114
self.qosClass = qosClass
115115
self.relativePriority = relativePriority
116116
}
117-
}
118117

119-
public func ==(a: DispatchQoS, b: DispatchQoS) -> Bool {
120-
return a.qosClass == b.qosClass && a.relativePriority == b.relativePriority
118+
public static func ==(a: DispatchQoS, b: DispatchQoS) -> Bool {
119+
return a.qosClass == b.qosClass && a.relativePriority == b.relativePriority
120+
}
121121
}
122122

123123
///

stdlib/public/SDK/ObjectiveC/ObjectiveC.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ public struct Selector : ExpressibleByStringLiteral {
112112
}
113113
}
114114

115-
public func ==(lhs: Selector, rhs: Selector) -> Bool {
116-
return sel_isEqual(lhs, rhs)
117-
}
118-
119115
extension Selector : Equatable, Hashable {
116+
public static func ==(lhs: Selector, rhs: Selector) -> Bool {
117+
return sel_isEqual(lhs, rhs)
118+
}
119+
120120
/// The hash value.
121121
///
122122
/// **Axiom:** `x == y` implies `x.hashValue == y.hashValue`
@@ -199,6 +199,10 @@ public var NO: ObjCBool {
199199
// FIXME: what about NSObjectProtocol?
200200

201201
extension NSObject : Equatable, Hashable {
202+
public static func == (lhs: NSObject, rhs: NSObject) -> Bool {
203+
return lhs.isEqual(rhs)
204+
}
205+
202206
/// The hash value.
203207
///
204208
/// **Axiom:** `x == y` implies `x.hashValue == y.hashValue`
@@ -212,10 +216,6 @@ extension NSObject : Equatable, Hashable {
212216
}
213217
}
214218

215-
public func == (lhs: NSObject, rhs: NSObject) -> Bool {
216-
return lhs.isEqual(rhs)
217-
}
218-
219219
extension NSObject : CVarArg {
220220
/// Transform `self` into a series of machine words that can be
221221
/// appropriately interpreted by C varargs

stdlib/public/SDK/UIKit/UIKit.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,24 @@ public extension UIOffset {
3939
// Equatable types.
4040
//===----------------------------------------------------------------------===//
4141

42-
@_transparent // @fragile
43-
public func == (lhs: UIEdgeInsets, rhs: UIEdgeInsets) -> Bool {
44-
return lhs.top == rhs.top &&
45-
lhs.left == rhs.left &&
46-
lhs.bottom == rhs.bottom &&
47-
lhs.right == rhs.right
42+
extension UIEdgeInsets : Equatable {
43+
@_transparent // @fragile
44+
public static func == (lhs: UIEdgeInsets, rhs: UIEdgeInsets) -> Bool {
45+
return lhs.top == rhs.top &&
46+
lhs.left == rhs.left &&
47+
lhs.bottom == rhs.bottom &&
48+
lhs.right == rhs.right
49+
}
4850
}
4951

50-
extension UIEdgeInsets : Equatable {}
51-
52-
@_transparent // @fragile
53-
public func == (lhs: UIOffset, rhs: UIOffset) -> Bool {
54-
return lhs.horizontal == rhs.horizontal &&
55-
lhs.vertical == rhs.vertical
52+
extension UIOffset : Equatable {
53+
@_transparent // @fragile
54+
public static func == (lhs: UIOffset, rhs: UIOffset) -> Bool {
55+
return lhs.horizontal == rhs.horizontal &&
56+
lhs.vertical == rhs.vertical
57+
}
5658
}
5759

58-
extension UIOffset : Equatable {}
59-
6060
//===----------------------------------------------------------------------===//
6161
// Numeric backed types
6262
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)