Skip to content

Commit ca5c65f

Browse files
natecook1000airspeedswift
authored andcommitted
[stdlib] Nest some additional operators (#9646)
1 parent 89515f8 commit ca5c65f

File tree

6 files changed

+60
-64
lines changed

6 files changed

+60
-64
lines changed

stdlib/public/core/BridgeObjectiveC.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,14 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
469469
guard let unwrapped = from else { return nil }
470470
self.init(unwrapped)
471471
}
472+
473+
@_transparent
474+
public static func == (
475+
lhs: AutoreleasingUnsafeMutablePointer,
476+
rhs: AutoreleasingUnsafeMutablePointer
477+
) -> Bool {
478+
return Bool(Builtin.cmp_eq_RawPointer(lhs._rawValue, rhs._rawValue))
479+
}
472480
}
473481

474482
extension UnsafeMutableRawPointer {
@@ -523,14 +531,6 @@ extension AutoreleasingUnsafeMutablePointer : CustomDebugStringConvertible {
523531
}
524532
}
525533

526-
@_transparent
527-
public func == <Pointee>(
528-
lhs: AutoreleasingUnsafeMutablePointer<Pointee>,
529-
rhs: AutoreleasingUnsafeMutablePointer<Pointee>
530-
) -> Bool {
531-
return Bool(Builtin.cmp_eq_RawPointer(lhs._rawValue, rhs._rawValue))
532-
}
533-
534534
@_fixed_layout
535535
@_versioned
536536
internal struct _CocoaFastEnumerationStackBuf {

stdlib/public/core/DropWhile.swift.gyb

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,18 @@ extension LazySequenceProtocol {
103103
public struct LazyDropWhileIndex<Base : Collection> : Comparable {
104104
/// The position corresponding to `self` in the underlying collection.
105105
public let base: Base.Index
106-
}
107106

108-
public func == <Base>(
109-
lhs: LazyDropWhileIndex<Base>,
110-
rhs: LazyDropWhileIndex<Base>
111-
) -> Bool {
112-
return lhs.base == rhs.base
113-
}
107+
public static func == (
108+
lhs: LazyDropWhileIndex, rhs: LazyDropWhileIndex
109+
) -> Bool {
110+
return lhs.base == rhs.base
111+
}
114112

115-
public func < <Base>(
116-
lhs: LazyDropWhileIndex<Base>,
117-
rhs: LazyDropWhileIndex<Base>
118-
) -> Bool {
119-
return lhs.base < rhs.base
113+
public static func < (
114+
lhs: LazyDropWhileIndex, rhs: LazyDropWhileIndex
115+
) -> Bool {
116+
return lhs.base < rhs.base
117+
}
120118
}
121119

122120
% for Traversal in ['Forward', 'Bidirectional']:

stdlib/public/core/FloatingPoint.swift.gyb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,12 +1424,12 @@ public enum FloatingPointRoundingRule {
14241424
case awayFromZero
14251425
}
14261426

1427-
@_transparent
1428-
public func == <T : FloatingPoint>(lhs: T, rhs: T) -> Bool {
1429-
return lhs.isEqual(to: rhs)
1430-
}
1431-
14321427
extension FloatingPoint {
1428+
@_transparent
1429+
public static func == (lhs: Self, rhs: Self) -> Bool {
1430+
return lhs.isEqual(to: rhs)
1431+
}
1432+
14331433
@_transparent
14341434
public static func < (lhs: Self, rhs: Self) -> Bool {
14351435
return lhs.isLess(than: rhs)

stdlib/public/core/ManagedBuffer.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -427,17 +427,16 @@ public struct ManagedBufferPointer<Header, Element> : Equatable {
427427
_headerOffset + MemoryLayout<Header>.size,
428428
toAlignment: MemoryLayout<Element>.alignment)
429429
}
430+
431+
public static func == (
432+
lhs: ManagedBufferPointer, rhs: ManagedBufferPointer
433+
) -> Bool {
434+
return lhs._address == rhs._address
435+
}
430436

431437
internal var _nativeBuffer: Builtin.NativeObject
432438
}
433439

434-
public func == <Header, Element>(
435-
lhs: ManagedBufferPointer<Header, Element>,
436-
rhs: ManagedBufferPointer<Header, Element>
437-
) -> Bool {
438-
return lhs._address == rhs._address
439-
}
440-
441440
// FIXME: when our calling convention changes to pass self at +0,
442441
// inout should be dropped from the arguments to these functions.
443442
// FIXME(docs): isKnownUniquelyReferenced should check weak/unowned counts too,

stdlib/public/core/PrefixWhile.swift.gyb

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -111,33 +111,31 @@ public struct LazyPrefixWhileIndex<Base : Collection> : Comparable {
111111
internal init(endOf: Base) {
112112
self._value = .pastEnd
113113
}
114-
}
115114

116-
public func == <Base>(
117-
lhs: LazyPrefixWhileIndex<Base>,
118-
rhs: LazyPrefixWhileIndex<Base>
119-
) -> Bool {
120-
switch (lhs._value, rhs._value) {
121-
case let (.index(l), .index(r)):
122-
return l == r
123-
case (.pastEnd, .pastEnd):
124-
return true
125-
default:
126-
return false
115+
public static func == (
116+
lhs: LazyPrefixWhileIndex, rhs: LazyPrefixWhileIndex
117+
) -> Bool {
118+
switch (lhs._value, rhs._value) {
119+
case let (.index(l), .index(r)):
120+
return l == r
121+
case (.pastEnd, .pastEnd):
122+
return true
123+
default:
124+
return false
125+
}
127126
}
128-
}
129127

130-
public func < <Base>(
131-
lhs: LazyPrefixWhileIndex<Base>,
132-
rhs: LazyPrefixWhileIndex<Base>
133-
) -> Bool {
134-
switch (lhs._value, rhs._value) {
135-
case let (.index(l), .index(r)):
136-
return l < r
137-
case (.index, .pastEnd):
138-
return true
139-
default:
140-
return false
128+
public static func < (
129+
lhs: LazyPrefixWhileIndex, rhs: LazyPrefixWhileIndex
130+
) -> Bool {
131+
switch (lhs._value, rhs._value) {
132+
case let (.index(l), .index(r)):
133+
return l < r
134+
case (.index, .pastEnd):
135+
return true
136+
default:
137+
return false
138+
}
141139
}
142140
}
143141

stdlib/public/core/Stride.swift.gyb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,16 @@ public protocol ${Self} : ${Conformance} {
5555

5656
% end
5757

58-
/// Compare two `Strideable`s.
59-
@_inlineable
60-
public func < <T : Strideable>(x: T, y: T) -> Bool {
61-
return x.distance(to: y) > 0
62-
}
58+
extension Strideable {
59+
@_inlineable
60+
public static func < (x: Self, y: Self) -> Bool {
61+
return x.distance(to: y) > 0
62+
}
6363

64-
@_inlineable
65-
public func == <T : Strideable>(x: T, y: T) -> Bool {
66-
return x.distance(to: y) == 0
64+
@_inlineable
65+
public static func == (x: Self, y: Self) -> Bool {
66+
return x.distance(to: y) == 0
67+
}
6768
}
6869

6970
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)