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:
aryan-25 authored and GitHub committed 2025-12-15 17:36:11 +00:00
1 parent 27146d4844
commit a1605a3303
16 files changed
+56 -51

No files matched your search

@@ -59,7 +59,7 @@ public final class WebSocketFrameEncoder: ChannelOutboundHandler {
}
public func write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?) {
let data = Self.unwrapOutboundIn(data)
let data = WebSocketFrameEncoder.unwrapOutboundIn(data)
// First, we explode the frame structure and apply the mask.
let frameHeader = FrameHeader(frame: data)
@@ -77,13 +77,13 @@ public final class WebSocketFrameEncoder: ChannelOutboundHandler {
if !unwrappedExtensionData.prependFrameHeaderIfPossible(frameHeader) {
self.writeSeparateHeaderBuffer(frameHeader, context: context)
}
context.write(Self.wrapOutboundOut(unwrappedExtensionData), promise: nil)
context.write(WebSocketFrameEncoder.wrapOutboundOut(unwrappedExtensionData), promise: nil)
} else if !applicationData.prependFrameHeaderIfPossible(frameHeader) {
self.writeSeparateHeaderBuffer(frameHeader, context: context)
}
// Ok, now we need to write the application data buffer.
context.write(Self.wrapOutboundOut(applicationData), promise: promise)
context.write(WebSocketFrameEncoder.wrapOutboundOut(applicationData), promise: promise)
}
/// Applies the websocket masking operation based on the passed byte buffers.
@@ -119,7 +119,7 @@ public final class WebSocketFrameEncoder: ChannelOutboundHandler {
// Ok, frame header away! Before we send it we save it back onto ourselves in case we get recursively called.
self.headerBuffer = buffer
context.write(Self.wrapOutboundOut(buffer), promise: nil)
context.write(WebSocketFrameEncoder.wrapOutboundOut(buffer), promise: nil)
}
}