@@ -54,16 +54,16 @@ extension HTTPClientRequest {
54
54
55
55
@available ( macOS 10 . 15 , iOS 13 . 0 , watchOS 6 . 0 , tvOS 13 . 0 , * )
56
56
extension HTTPClientRequest . Body {
57
- public static func byteBuffer( _ byteBuffer: ByteBuffer ) -> Self {
57
+
58
+ public static func bytes( _ byteBuffer: ByteBuffer ) -> Self {
58
59
self . init ( . byteBuffer( byteBuffer) )
59
60
}
60
61
61
62
@inlinable
62
- public static func bytes< Bytes: Sequence > (
63
- length: Int ? ,
63
+ public static func bytes< Bytes: RandomAccessCollection > (
64
64
_ bytes: Bytes
65
65
) -> Self where Bytes. Element == UInt8 {
66
- self . init ( . sequence( length: length , canBeConsumedMultipleTimes: false ) { allocator in
66
+ self . init ( . sequence( length: bytes . count , canBeConsumedMultipleTimes: true ) { allocator in
67
67
if let buffer = bytes. withContiguousStorageIfAvailable ( { allocator. buffer ( bytes: $0) } ) {
68
68
// fastpath
69
69
return buffer
@@ -72,27 +72,13 @@ extension HTTPClientRequest.Body {
72
72
return allocator. buffer ( bytes: bytes)
73
73
} )
74
74
}
75
-
75
+
76
76
@inlinable
77
- public static func bytes< Bytes: Collection > (
77
+ public static func bytes< Bytes: Sequence > (
78
78
length: Int ? ,
79
79
_ bytes: Bytes
80
80
) -> Self where Bytes. Element == UInt8 {
81
- self . init ( . sequence( length: length, canBeConsumedMultipleTimes: true ) { allocator in
82
- if let buffer = bytes. withContiguousStorageIfAvailable ( { allocator. buffer ( bytes: $0) } ) {
83
- // fastpath
84
- return buffer
85
- }
86
- // potentially really slow path
87
- return allocator. buffer ( bytes: bytes)
88
- } )
89
- }
90
-
91
- @inlinable
92
- public static func bytes< Bytes: RandomAccessCollection > (
93
- _ bytes: Bytes
94
- ) -> Self where Bytes. Element == UInt8 {
95
- self . init ( . sequence( length: bytes. count, canBeConsumedMultipleTimes: true ) { allocator in
81
+ self . init ( . sequence( length: length, canBeConsumedMultipleTimes: bytes is Collection ) { allocator in
96
82
if let buffer = bytes. withContiguousStorageIfAvailable ( { allocator. buffer ( bytes: $0) } ) {
97
83
// fastpath
98
84
return buffer
0 commit comments