Skip to content

Commit 38aeae5

Browse files
ikesyoandersio
authored andcommitted
[gardening] Remove unnecessary conditional code (#541)
1 parent eeb62fc commit 38aeae5

File tree

9 files changed

+26
-70
lines changed

9 files changed

+26
-70
lines changed

Sources/FoundationExtensions.swift

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -87,61 +87,35 @@ extension Date {
8787

8888
extension DispatchTimeInterval {
8989
internal var timeInterval: TimeInterval {
90-
#if swift(>=3.2)
91-
switch self {
92-
case let .seconds(s):
93-
return TimeInterval(s)
94-
case let .milliseconds(ms):
95-
return TimeInterval(TimeInterval(ms) / 1000.0)
96-
case let .microseconds(us):
97-
return TimeInterval(Int64(us) * Int64(NSEC_PER_USEC)) / TimeInterval(NSEC_PER_SEC)
98-
case let .nanoseconds(ns):
99-
return TimeInterval(ns) / TimeInterval(NSEC_PER_SEC)
100-
case .never:
101-
return .infinity
102-
}
103-
#else
104-
switch self {
105-
case let .seconds(s):
106-
return TimeInterval(s)
107-
case let .milliseconds(ms):
108-
return TimeInterval(TimeInterval(ms) / 1000.0)
109-
case let .microseconds(us):
110-
return TimeInterval(Int64(us) * Int64(NSEC_PER_USEC)) / TimeInterval(NSEC_PER_SEC)
111-
case let .nanoseconds(ns):
112-
return TimeInterval(ns) / TimeInterval(NSEC_PER_SEC)
113-
}
114-
#endif
90+
switch self {
91+
case let .seconds(s):
92+
return TimeInterval(s)
93+
case let .milliseconds(ms):
94+
return TimeInterval(TimeInterval(ms) / 1000.0)
95+
case let .microseconds(us):
96+
return TimeInterval(Int64(us) * Int64(NSEC_PER_USEC)) / TimeInterval(NSEC_PER_SEC)
97+
case let .nanoseconds(ns):
98+
return TimeInterval(ns) / TimeInterval(NSEC_PER_SEC)
99+
case .never:
100+
return .infinity
101+
}
115102
}
116103

117104
// This was added purely so that our test scheduler to "go backwards" in
118105
// time. See `TestScheduler.rewind(by interval: DispatchTimeInterval)`.
119106
internal static prefix func -(lhs: DispatchTimeInterval) -> DispatchTimeInterval {
120-
#if swift(>=3.2)
121-
switch lhs {
122-
case let .seconds(s):
123-
return .seconds(-s)
124-
case let .milliseconds(ms):
125-
return .milliseconds(-ms)
126-
case let .microseconds(us):
127-
return .microseconds(-us)
128-
case let .nanoseconds(ns):
129-
return .nanoseconds(-ns)
130-
case .never:
131-
return .never
132-
}
133-
#else
134-
switch lhs {
135-
case let .seconds(s):
136-
return .seconds(-s)
137-
case let .milliseconds(ms):
138-
return .milliseconds(-ms)
139-
case let .microseconds(us):
140-
return .microseconds(-us)
141-
case let .nanoseconds(ns):
142-
return .nanoseconds(-ns)
143-
}
144-
#endif
107+
switch lhs {
108+
case let .seconds(s):
109+
return .seconds(-s)
110+
case let .milliseconds(ms):
111+
return .milliseconds(-ms)
112+
case let .microseconds(us):
113+
return .microseconds(-us)
114+
case let .nanoseconds(ns):
115+
return .nanoseconds(-ns)
116+
case .never:
117+
return .never
118+
}
145119
}
146120

147121
/// Scales a time interval by the given scalar specified in `rhs`.

Sources/Property.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ extension PropertyProtocol {
102102
return lift { $0.map(transform) }
103103
}
104104

105-
#if swift(>=3.2)
106105
/// Maps the current value and all subsequent values to a new property
107106
/// by applying a key path.
108107
///
@@ -113,7 +112,6 @@ extension PropertyProtocol {
113112
public func map<U>(_ keyPath: KeyPath<Value, U>) -> Property<U> {
114113
return lift { $0.map(keyPath) }
115114
}
116-
#endif
117115

118116
/// Combines the current value and the subsequent values of two `Property`s in
119117
/// the manner described by `Signal.combineLatest(with:)`.

Sources/Signal.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,6 @@ extension Signal {
554554
return flatMapEvent(Signal.Event.map(transform))
555555
}
556556

557-
#if swift(>=3.2)
558557
/// Map each value in the signal to a new value by applying a key path.
559558
///
560559
/// - parameters:
@@ -564,7 +563,6 @@ extension Signal {
564563
public func map<U>(_ keyPath: KeyPath<Value, U>) -> Signal<U, Error> {
565564
return map { $0[keyPath: keyPath] }
566565
}
567-
#endif
568566

569567
/// Map errors in the signal to a new error.
570568
///

Sources/SignalProducer.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,6 @@ extension SignalProducer {
809809
return core.flatMapEvent(Signal.Event.map(transform))
810810
}
811811

812-
#if swift(>=3.2)
813812
/// Map each value in the producer to a new value by applying a key path.
814813
///
815814
/// - parameters:
@@ -819,7 +818,6 @@ extension SignalProducer {
819818
public func map<U>(_ keyPath: KeyPath<Value, U>) -> SignalProducer<U, Error> {
820819
return core.flatMapEvent(Signal.Event.filterMap { $0[keyPath: keyPath] })
821820
}
822-
#endif
823821

824822
/// Map errors in the producer to a new error.
825823
///

Sources/UnidirectionalBinding.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ public struct BindingTarget<Value>: BindingTargetProvider {
149149
}
150150
}
151151

152-
#if swift(>=3.2)
153152
/// Creates a binding target which consumes values on the specified scheduler.
154153
///
155154
/// If no scheduler is specified, the binding target would consume the value
@@ -163,5 +162,4 @@ public struct BindingTarget<Value>: BindingTargetProvider {
163162
public init<Object: AnyObject>(on scheduler: Scheduler = ImmediateScheduler(), lifetime: Lifetime, object: Object, keyPath: WritableKeyPath<Object, Value>) {
164163
self.init(on: scheduler, lifetime: lifetime) { [weak object] in object?[keyPath: keyPath] = $0 }
165164
}
166-
#endif
167165
}

Tests/ReactiveSwiftTests/FoundationExtensionsSpec.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,15 @@ class FoundationExtensionsSpec: QuickSpec {
103103

104104
expect(DispatchTimeInterval.milliseconds(500).timeInterval).to(beCloseTo(0.5))
105105
expect(DispatchTimeInterval.milliseconds(250).timeInterval).to(beCloseTo(0.25))
106-
#if swift(>=3.2)
107-
expect(DispatchTimeInterval.never.timeInterval) == Double.infinity
108-
#endif
106+
expect(DispatchTimeInterval.never.timeInterval) == Double.infinity
109107
}
110108

111109
it("should negate as you'd hope") {
112110
expect((-DispatchTimeInterval.seconds(1)).timeInterval).to(beCloseTo(-1.0))
113111
expect((-DispatchTimeInterval.milliseconds(1)).timeInterval).to(beCloseTo(-0.001))
114112
expect((-DispatchTimeInterval.microseconds(1)).timeInterval).to(beCloseTo(-0.000001, within: 0.0000001))
115113
expect((-DispatchTimeInterval.nanoseconds(1)).timeInterval).to(beCloseTo(-0.000000001, within: 0.0000000001))
116-
#if swift(>=3.2)
117-
expect((-DispatchTimeInterval.never).timeInterval) == Double.infinity
118-
#endif
114+
expect((-DispatchTimeInterval.never).timeInterval) == Double.infinity
119115
}
120116
}
121117
}

Tests/ReactiveSwiftTests/PropertySpec.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,6 @@ class PropertySpec: QuickSpec {
733733
expect(mappedProperty.value) == 3
734734
}
735735

736-
#if swift(>=3.2)
737736
it("should work with key paths") {
738737
let property = MutableProperty("foo")
739738
let mappedProperty = property.map(\.count)
@@ -742,7 +741,6 @@ class PropertySpec: QuickSpec {
742741
property.value = "foobar"
743742
expect(mappedProperty.value) == 6
744743
}
745-
#endif
746744
}
747745

748746
describe("combineLatest") {

Tests/ReactiveSwiftTests/SignalSpec.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,6 @@ class SignalSpec: QuickSpec {
506506
expect(lastValue) == "2"
507507
}
508508

509-
#if swift(>=3.2)
510509
it("should support key paths") {
511510
let (signal, observer) = Signal<String, NoError>.pipe()
512511
let mappedSignal = signal.map(\String.count)
@@ -524,7 +523,6 @@ class SignalSpec: QuickSpec {
524523
observer.send(value: "foobar")
525524
expect(lastValue) == 6
526525
}
527-
#endif
528526
}
529527

530528
describe("mapError") {

Tests/ReactiveSwiftTests/UnidirectionalBindingSpec.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ class UnidirectionalBindingSpec: QuickSpec {
8080
}
8181
}
8282

83-
#if swift(>=3.2)
8483
describe("key path binding target") {
8584
var target: BindingTarget<Int>!
8685
var object: Object!
@@ -112,7 +111,6 @@ class UnidirectionalBindingSpec: QuickSpec {
112111
expect(object.value) == 2
113112
}
114113
}
115-
#endif
116114

117115
it("should not deadlock on the same queue") {
118116
var value: Int?

0 commit comments

Comments
 (0)