mirror of
https://github.com/apple/swift-nio
synced 2026-11-28 05:14:23 +00:00
Motivation: Often we know ahead of time that we will need to write a certain number of bytes into a buffer. It is useful to ensure the buffer has enough capacity to store these bytes without causing unnecessary allocations. However, `reserveCapacity()` is defined in terms of the capacity of the buffer and it's can be easy to forget that this does not take into account the writer index. Modifications: - Add a method which reserves enough capacity to write at least the specified number of bytes. - Update `writeWithUnsafeMutableBytes(minimumWritableBytes:body:)` to use the new method. Result: It's easier for users to reserve enough writable capacity ahead of time.