mirror of
https://github.com/apple/swift-nio-imap
synced 2026-11-30 05:28:46 +00:00
Don't allocate a promise per buffer for writes without one
This commit is contained in:
2 files changed
+8
-3
No files matched your search
@@ -193,12 +193,16 @@ public final class IMAPClientHandler: ChannelDuplexHandler {
|
||||
context: ChannelHandlerContext
|
||||
) {
|
||||
let outbound = self.wrapOutboundOut(bytes)
|
||||
guard let promise = chunk.promise else {
|
||||
context.write(outbound, promise: nil)
|
||||
return
|
||||
}
|
||||
if position == .last, chunk.shouldSucceedPromise {
|
||||
context.write(outbound, promise: chunk.promise)
|
||||
context.write(outbound, promise: promise)
|
||||
} else {
|
||||
// Not the last buffer, or a chunk that will only be finished by a later one: the promise
|
||||
// must not succeed yet, but a failure anywhere has to reach it.
|
||||
context.write(outbound).cascadeFailure(to: chunk.promise)
|
||||
context.write(outbound).cascadeFailure(to: promise)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -140,7 +140,8 @@ public final class IMAPServerHandler: ChannelDuplexHandler {
|
||||
let buffers = bytes.makeOutboundBuffers()
|
||||
for (index, buffer) in buffers.enumerated() {
|
||||
let outbound = self.wrapOutboundOut(buffer)
|
||||
if index == buffers.count - 1 {
|
||||
// Without a promise there is nothing to order, and no need to allocate one per write.
|
||||
if index == buffers.count - 1 || promise == nil {
|
||||
context.write(outbound, promise: promise)
|
||||
} else {
|
||||
context.write(outbound).cascadeFailure(to: promise)
|
||||
|
||||
Reference in new issue
Block a user