From a5866a196ff508c8aa26b794abff8e90a245d2fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Wei=C3=9F?= Date: Thu, 26 Apr 2018 15:58:29 +0100 Subject: [PATCH] two missing @_inlineables Motivation: @_inlineable is important for at least all performance sensitive functions that use generics and/or closures. Modifications: added two missing @_inlineable Result: fewer allocations (not measurable because https://bugs.swift.org/browse/SR-7542) --- Sources/NIO/ByteBuffer-core.swift | 1 + Sources/NIOFoundationCompat/ByteBuffer-foundation.swift | 1 + 2 files changed, 2 insertions(+) diff --git a/Sources/NIO/ByteBuffer-core.swift b/Sources/NIO/ByteBuffer-core.swift index 6d74396ba5..5071cf9047 100644 --- a/Sources/NIO/ByteBuffer-core.swift +++ b/Sources/NIO/ByteBuffer-core.swift @@ -624,6 +624,7 @@ extension ByteBuffer: CustomStringConvertible { /// A `Collection` that is contiguously layed out in memory and can therefore be duplicated using `memcpy`. public protocol ContiguousCollection: Collection { + @_inlineable func withUnsafeBytes(_ body: (UnsafeRawBufferPointer) throws -> R) rethrows -> R } diff --git a/Sources/NIOFoundationCompat/ByteBuffer-foundation.swift b/Sources/NIOFoundationCompat/ByteBuffer-foundation.swift index 084ffc7ca8..6f35f300fe 100644 --- a/Sources/NIOFoundationCompat/ByteBuffer-foundation.swift +++ b/Sources/NIOFoundationCompat/ByteBuffer-foundation.swift @@ -30,6 +30,7 @@ import struct Foundation.Data */ extension Data: ContiguousCollection { + @_inlineable public func withUnsafeBytes(_ body: (UnsafeRawBufferPointer) throws -> R) rethrows -> R { return try self.withUnsafeBytes { (ptr: UnsafePointer) -> R in try body(UnsafeRawBufferPointer(start: ptr, count: self.count))