mirror of
https://github.com/apple/swift-nio
synced 2026-11-25 04:47:49 +00:00
Use explicit class name in all Self.[un]wrap{In}{Out}bound{In}{Out} calls (#3463)
### Motivation:
Swift does not currently generic specialize static methods on final
classes that have no parent classes when the method is implemented in a
protocol. This means that calling such methods through `Self` will not
involve a generic specialization, whereas using the explicit type name
will.
This pattern manifests in the `[un]wrap{In}{Out}bound{In}{Out}` static
methods defined in the
[`ChannelInboundHandler`](https://github.com/apple/swift-nio/blob/27146d484478b1bb0f150e848758f3a34ed9cbd0/Sources/NIOCore/TypeAssistedChannelHandler.swift#L60)
and
[`ChannelOutboundHandler`](https://github.com/apple/swift-nio/blob/27146d484478b1bb0f150e848758f3a34ed9cbd0/Sources/NIOCore/TypeAssistedChannelHandler.swift#L95)
protocols and their use from all channel handler classes. As such, we
should replace the `Self` part in all
`Self.[un]wrap{In}{Out}bound{In}{Out}` calls with the explicit class
name.
### Modifications:
Replaced all `Self.[un]wrap{In}{Out}bound{In}{Out}` calls to use the
explicit class name.
### Result:
Eliminates unnecessary overhead.
This commit is contained in:
1 parent
27146d4844
commit
a1605a3303
16 files changed
+56
-51
No files matched your search
@@ -202,7 +202,7 @@ public final class HTTPRequestEncoder: ChannelOutboundHandler, RemovableChannelH
|
||||
}
|
||||
|
||||
public func write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?) {
|
||||
switch Self.unwrapOutboundIn(data) {
|
||||
switch HTTPRequestEncoder.unwrapOutboundIn(data) {
|
||||
case .head(var request):
|
||||
assert(
|
||||
!(request.headers.contains(name: "content-length")
|
||||
@@ -221,7 +221,7 @@ public final class HTTPRequestEncoder: ChannelOutboundHandler, RemovableChannelH
|
||||
}
|
||||
|
||||
writeHead(
|
||||
wrapOutboundOut: Self.wrapOutboundOut,
|
||||
wrapOutboundOut: HTTPRequestEncoder.wrapOutboundOut,
|
||||
writeStartLine: { buffer in
|
||||
buffer.write(request: request)
|
||||
},
|
||||
@@ -231,7 +231,7 @@ public final class HTTPRequestEncoder: ChannelOutboundHandler, RemovableChannelH
|
||||
)
|
||||
case .body(let bodyPart):
|
||||
writeChunk(
|
||||
wrapOutboundOut: Self.wrapOutboundOut,
|
||||
wrapOutboundOut: HTTPRequestEncoder.wrapOutboundOut,
|
||||
context: context,
|
||||
isChunked: self.isChunked,
|
||||
chunk: bodyPart,
|
||||
@@ -239,7 +239,7 @@ public final class HTTPRequestEncoder: ChannelOutboundHandler, RemovableChannelH
|
||||
)
|
||||
case .end(let trailers):
|
||||
writeTrailers(
|
||||
wrapOutboundOut: Self.wrapOutboundOut,
|
||||
wrapOutboundOut: HTTPRequestEncoder.wrapOutboundOut,
|
||||
context: context,
|
||||
isChunked: self.isChunked,
|
||||
trailers: trailers,
|
||||
@@ -292,7 +292,7 @@ public final class HTTPResponseEncoder: ChannelOutboundHandler, RemovableChannel
|
||||
}
|
||||
|
||||
public func write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?) {
|
||||
switch Self.unwrapOutboundIn(data) {
|
||||
switch HTTPResponseEncoder.unwrapOutboundIn(data) {
|
||||
case .head(var response):
|
||||
assert(
|
||||
!(response.headers.contains(name: "content-length")
|
||||
@@ -312,7 +312,7 @@ public final class HTTPResponseEncoder: ChannelOutboundHandler, RemovableChannel
|
||||
}
|
||||
|
||||
writeHead(
|
||||
wrapOutboundOut: Self.wrapOutboundOut,
|
||||
wrapOutboundOut: HTTPResponseEncoder.wrapOutboundOut,
|
||||
writeStartLine: { buffer in
|
||||
buffer.write(response: response)
|
||||
},
|
||||
@@ -322,7 +322,7 @@ public final class HTTPResponseEncoder: ChannelOutboundHandler, RemovableChannel
|
||||
)
|
||||
case .body(let bodyPart):
|
||||
writeChunk(
|
||||
wrapOutboundOut: Self.wrapOutboundOut,
|
||||
wrapOutboundOut: HTTPResponseEncoder.wrapOutboundOut,
|
||||
context: context,
|
||||
isChunked: self.isChunked,
|
||||
chunk: bodyPart,
|
||||
@@ -330,7 +330,7 @@ public final class HTTPResponseEncoder: ChannelOutboundHandler, RemovableChannel
|
||||
)
|
||||
case .end(let trailers):
|
||||
writeTrailers(
|
||||
wrapOutboundOut: Self.wrapOutboundOut,
|
||||
wrapOutboundOut: HTTPResponseEncoder.wrapOutboundOut,
|
||||
context: context,
|
||||
isChunked: self.isChunked,
|
||||
trailers: trailers,
|
||||
|
||||
Reference in new issue
Block a user