mirror of
https://github.com/apple/swift-nio
synced 2026-11-27 05:04:22 +00:00
Prefer if case over switch
Motivation:
There are quite a few `switch`es that cover just two cases. Explicitly state this via an `if case` + `else` structure.
Modifications:
Changes something like:
switch a {
case .b:
return c
default:
return d
}
to
if case .b = a {
return c
} else {
return d
}
Result:
This should prevent misinterpretation and thus potential bugs in the future.
This commit is contained in:
1 parent
4c89a4e675
commit
a095decbc2
11 files changed
+46
-69
No files matched your search
@@ -995,11 +995,10 @@ extension HTTPResponseStatus {
|
||||
/// - Parameter buffer: A buffer to write the serialized bytes into. Will increment
|
||||
/// the writer index of this buffer.
|
||||
func write(buffer: inout ByteBuffer) {
|
||||
switch self {
|
||||
case .ok:
|
||||
if case .ok = self {
|
||||
// Optimize for 200 ok, which should be the most likely code (...hopefully).
|
||||
buffer.write(staticString: status200)
|
||||
default:
|
||||
} else {
|
||||
buffer.write(string: String(code))
|
||||
buffer.write(string: " ")
|
||||
buffer.write(string: reasonPhrase)
|
||||
|
||||
Reference in new issue
Block a user