mirror of
https://github.com/apple/swift-nio
synced 2026-11-28 05:14:23 +00:00
Directly use the IOEvent to init a SelectorEvent when using KQueue (#238)
Motivation: When using KQueue we directly can tell what IOEvent we want to use in SelectorEvent without and branching. Modifications: Add new init method to SelectorEvent that takes the IOEvent directly and use it when using KQueue Result: Less branching per event when using KQueue
This commit is contained in:
1 parent
774f298dca
commit
94edbad2be
1 file changed
+15
-5
@@ -398,11 +398,11 @@ final class Selector<R: Registration> {
|
||||
break
|
||||
case EVFILT_READ:
|
||||
if let registration = registrations[Int(ev.ident)] {
|
||||
try body((SelectorEvent(readable: true, writable: false, registration: registration)))
|
||||
try body((SelectorEvent(io: .read, registration: registration)))
|
||||
}
|
||||
case EVFILT_WRITE:
|
||||
if let registration = registrations[Int(ev.ident)] {
|
||||
try body((SelectorEvent(readable: false, writable: true, registration: registration)))
|
||||
try body((SelectorEvent(io: .write, registration: registration)))
|
||||
}
|
||||
default:
|
||||
// We only use EVFILT_USER, EVFILT_READ and EVFILT_WRITE.
|
||||
@@ -466,6 +466,16 @@ struct SelectorEvent<R> {
|
||||
public let registration: R
|
||||
public let io: IOEvent
|
||||
|
||||
/// Create new instance
|
||||
///
|
||||
/// - parameters:
|
||||
/// - io: The `IOEvent` that triggered this event.
|
||||
/// - registration: The registration that belongs to the event.
|
||||
init(io: IOEvent, registration: R) {
|
||||
self.io = io
|
||||
self.registration = registration
|
||||
}
|
||||
|
||||
/// Create new instance
|
||||
///
|
||||
/// - parameters:
|
||||
@@ -474,11 +484,11 @@ struct SelectorEvent<R> {
|
||||
/// - registration: The registration that belongs to the event.
|
||||
init(readable: Bool, writable: Bool, registration: R) {
|
||||
if readable {
|
||||
io = writable ? .all : .read
|
||||
self.io = writable ? .all : .read
|
||||
} else if writable {
|
||||
io = .write
|
||||
self.io = .write
|
||||
} else {
|
||||
io = .none
|
||||
self.io = .none
|
||||
}
|
||||
self.registration = registration
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user