Skip to content

Commit dd41272

Browse files
committedJan 15, 2024
Fix code style
1 parent cfe2d28 commit dd41272

9 files changed

+22
-28
lines changed
 

‎Sources/Event/Epoll.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extension Descriptor {
1313
guard getrlimit(Int32(RLIMIT_NOFILE.rawValue), &rlim) >= 0 else {
1414
return 0
1515
}
16-
return Int(rlim.rlim_max);
16+
return Int(rlim.rlim_max)
1717
}
1818
}
1919

‎Sources/Event/Kqueue.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public struct TypeOptions: OptionSet {
5353
public static let write = TypeOptions(rawValue: Int16(EVFILT_WRITE))
5454
}
5555

56-
fileprivate struct FlagOptions: OptionSet {
56+
private struct FlagOptions: OptionSet {
5757
let rawValue: UInt16
5858

5959
static let add = FlagOptions(rawValue: UInt16(EV_ADD))

‎Sources/Event/Poller.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extension PollerProtocol {
2020
}
2121

2222
extension Poller: Equatable {
23-
public static func ==(lhs: Poller, rhs: Poller) -> Bool {
23+
public static func == (lhs: Poller, rhs: Poller) -> Bool {
2424
return lhs.descriptor == rhs.descriptor
2525
}
2626
}

‎Sources/Fiber/FiberLoop+Dispatch.swift

+3-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extension FiberLoop {
1919
guard try wait(for: fd.1, event: .write, deadline: deadline) == .ready
2020
else { throw Error.canceled }
2121

22-
var result: Result<T>? = nil
22+
var result: Result<T>?
2323

2424
let workItem = DispatchWorkItem(qos: qos) {
2525
fiber {
@@ -51,9 +51,8 @@ extension FiberLoop {
5151
fileprivate func pipe() throws -> (Descriptor, Descriptor) {
5252
var fd: (Int32, Int32) = (0, 0)
5353
try withUnsafeMutablePointer(to: &fd) { pointer in
54-
try pointer.withMemoryRebound(to: Int32.self, capacity: 2)
55-
{ pointer in
56-
guard Platform.pipe(pointer) != -1 else {
54+
try pointer.withMemoryRebound(to: Int32.self, capacity: 2) {
55+
guard Platform.pipe($0) != -1 else {
5756
throw SystemError()
5857
}
5958
}

‎Sources/Fiber/FiberLoop.swift

+10-14
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import Event
44
import Platform
55
import ListEntry
66

7-
@_exported import enum Event.IOEvent
8-
97
public class FiberLoop {
108
var poller = Poller()
119
var watchers: UnsafeMutableBufferPointer<Watchers>
@@ -32,7 +30,7 @@ public class FiberLoop {
3230
public class var current: FiberLoop {
3331
Thread.isMain
3432
? main
35-
: FiberLoop._current.get() { FiberLoop() }
33+
: FiberLoop._current.get { FiberLoop() }
3634
}
3735

3836
var deadline = Time.distantFuture
@@ -162,8 +160,8 @@ public class FiberLoop {
162160
public func wait(
163161
for socket: Descriptor,
164162
event: IOEvent,
165-
deadline: Time) throws -> Fiber.State
166-
{
163+
deadline: Time
164+
) throws -> Fiber.State {
167165
try insertWatcher(for: socket, event: event, deadline: deadline)
168166
scheduler.suspend()
169167
removeWatcher(for: socket, event: event)
@@ -212,11 +210,9 @@ public class FiberLoop {
212210
} else if deadline < sleeping.minDeadline! {
213211
sleeping.insert(currentFiber.pointee.watcherEntry)
214212
} else {
215-
for watcher in sleeping.pointee {
216-
if deadline < watcher.deadline {
217-
watcher.insert(currentFiber.pointee.watcherEntry)
218-
return
219-
}
213+
for watcher in sleeping.pointee where deadline < watcher.deadline {
214+
watcher.insert(currentFiber.pointee.watcherEntry)
215+
return
220216
}
221217
fatalError("unreachable")
222218
}
@@ -230,15 +226,15 @@ public class FiberLoop {
230226
extension UnsafeMutableBufferPointer where Element == FiberLoop.Watchers {
231227
typealias Watchers = FiberLoop.Watchers
232228

233-
subscript(_ descriptor: Descriptor) -> Watchers{
229+
subscript(_ descriptor: Descriptor) -> Watchers {
234230
get { self[Int(descriptor.rawValue)] }
235231
set { self[Int(descriptor.rawValue)] = newValue }
236232
}
237233

238234
static func allocate(
239235
repeating element: Watchers,
240-
count: Int) -> UnsafeMutableBufferPointer<Watchers>
241-
{
236+
count: Int
237+
) -> UnsafeMutableBufferPointer<Watchers> {
242238
let pointer = UnsafeMutablePointer<Watchers>.allocate(capacity: count)
243239
pointer.initialize(repeating: element, count: count)
244240

@@ -264,7 +260,7 @@ where Pointee == ListEntry<UnsafeMutablePointer<Fiber>> {
264260
}
265261

266262
extension FiberLoop: Equatable {
267-
public static func ==(lhs: FiberLoop, rhs: FiberLoop) -> Bool {
263+
public static func == (lhs: FiberLoop, rhs: FiberLoop) -> Bool {
268264
return lhs.poller == rhs.poller
269265
}
270266
}

‎Sources/Fiber/Scheduler.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class Scheduler {
1010
public class var current: Scheduler {
1111
Thread.isMain
1212
? main
13-
: Scheduler._current.get() { Scheduler() }
13+
: Scheduler._current.get { Scheduler() }
1414
}
1515

1616
init() {
@@ -98,8 +98,7 @@ public class Scheduler {
9898
}
9999

100100
@usableFromInline
101-
func schedule(fiber: UnsafeMutablePointer<Fiber>, state: Fiber.State)
102-
{
101+
func schedule(fiber: UnsafeMutablePointer<Fiber>, state: Fiber.State) {
103102
fiber.pointee.state = state
104103
ready.append(fiber)
105104
}

‎Tests/FiberTests/ChannelTests.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class ChannelTests: TestCase {
118118
func testChannelCloseHasReader() {
119119
let channel = Channel<Int>(capacity: 10)
120120

121-
var first: Int? = nil
121+
var first: Int?
122122
fiber {
123123
first = channel.read()
124124
}
@@ -138,7 +138,7 @@ class ChannelTests: TestCase {
138138
func testChannelCloseHasWaitingReader() {
139139
let channel = Channel<Int>()
140140

141-
var result: Optional<Int> = 42
141+
var result: Int? = 42
142142
fiber {
143143
result = channel.read()
144144
}

‎Tests/FiberTests/DispatchTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class DispatchTests: TestCase {
3838
struct TestError: Swift.Error, Equatable {
3939
let code: Int
4040
}
41-
var testError: TestError? = nil
41+
var testError: TestError?
4242

4343
fiber {
4444
do {

‎Tests/FiberTests/FiberLoopTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class FiberLoopTests: TestCase {
6464
}
6565

6666
func testPollDeadline() {
67-
var result: FiberLoop.Error? = nil
67+
var result: FiberLoop.Error?
6868

6969
fiber {
7070
do {

0 commit comments

Comments
 (0)
Please sign in to comment.