Skip to content

Commit 59355c9

Browse files
committed
Swift 5: ContiguousCollection => Collection
Not quite sure whether this produces a performance regression.
1 parent 681548a commit 59355c9

File tree

1 file changed

+54
-23
lines changed

1 file changed

+54
-23
lines changed

Sources/NIORedis/RESPChannelHandler.swift

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,27 @@ open class RESPChannelHandler : ChannelDuplexHandler {
132132
ctx.write(wrapOutboundOut(out), promise: promise)
133133
}
134134

135-
@inline(__always)
136-
final func encode<S: ContiguousCollection>(simpleString bytes: S,
137-
out: inout ByteBuffer)
138-
where S.Element == UInt8
139-
{
140-
out.write(integer : UInt8(43)) // +
141-
out.write(bytes : bytes)
142-
out.write(bytes : eol)
143-
}
135+
#if swift(>=5)
136+
@inline(__always)
137+
final func encode<S: Collection>(simpleString bytes: S,
138+
out: inout ByteBuffer)
139+
where S.Element == UInt8
140+
{
141+
out.writeInteger(UInt8(43)) // +
142+
out.writeBytes(bytes)
143+
out.writeBytes(eol)
144+
}
145+
#else
146+
@inline(__always)
147+
final func encode<S: ContiguousCollection>(simpleString bytes: S,
148+
out: inout ByteBuffer)
149+
where S.Element == UInt8
150+
{
151+
out.writeInteger(UInt8(43)) // +
152+
out.writeBytes(bytes)
153+
out.writeBytes(eol)
154+
}
155+
#endif
144156

145157
@inline(__always)
146158
final func encode(simpleString bytes: ByteBuffer, out: inout ByteBuffer) {
@@ -164,22 +176,41 @@ open class RESPChannelHandler : ChannelDuplexHandler {
164176
}
165177
}
166178

167-
@inline(__always)
168-
final func encode<S: ContiguousCollection>(bulkString bytes: S?,
169-
out: inout ByteBuffer)
170-
where S.Element == UInt8
171-
{
172-
if let s = bytes {
173-
out.write(integer : UInt8(36)) // $
174-
out.write(integerAsString : Int(s.count))
175-
out.write(bytes : eol)
176-
out.write(bytes : s)
177-
out.write(bytes : eol)
179+
#if swift(>=5)
180+
@inline(__always)
181+
final func encode<S: Collection>(bulkString bytes: S?,
182+
out: inout ByteBuffer)
183+
where S.Element == UInt8
184+
{
185+
if let s = bytes {
186+
out.writeInteger(UInt8(36)) // $
187+
out.write(integerAsString : Int(s.count))
188+
out.writeBytes(eol)
189+
out.writeBytes(s)
190+
out.writeBytes(eol)
191+
}
192+
else {
193+
out.writeBytes(nilString)
194+
}
178195
}
179-
else {
180-
out.write(bytes: nilString)
196+
#else
197+
@inline(__always)
198+
final func encode<S: ContiguousCollection>(bulkString bytes: S?,
199+
out: inout ByteBuffer)
200+
where S.Element == UInt8
201+
{
202+
if let s = bytes {
203+
out.writeInteger(UInt8(36)) // $
204+
out.write(integerAsString : Int(s.count))
205+
out.writeBytes(eol)
206+
out.writeBytes(s)
207+
out.writeBytes(eol)
208+
}
209+
else {
210+
out.writeBytes(nilString)
211+
}
181212
}
182-
}
213+
#endif
183214

184215
@inline(__always)
185216
final func encode(integer i: Int, out: inout ByteBuffer) {

0 commit comments

Comments
 (0)