Skip to content

Commit ad70fc0

Browse files
committed
Do not use @inline(__always)
Use @inlinable instead, or let the compiler be smart. Also make more public things @inlinable for speedz.
1 parent d111904 commit ad70fc0

File tree

6 files changed

+87
-88
lines changed

6 files changed

+87
-88
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# SwiftNIO Redis
22

3-
![Swift4](https://img.shields.io/badge/swift-4-blue.svg)
43
![Swift5](https://img.shields.io/badge/swift-5-blue.svg)
54
![macOS](https://img.shields.io/badge/os-macOS-green.svg?style=flat)
65
![tuxOS](https://img.shields.io/badge/os-tuxOS-green.svg?style=flat)

Sources/NIORedis/RESPChannelHandler.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ open class RESPChannelHandler : ChannelDuplexHandler {
133133
context.write(wrapOutboundOut(out), promise: promise)
134134
}
135135

136-
@inline(__always)
136+
@inlinable
137137
final func encode<S: Collection>(simpleString bytes: S,
138138
out: inout ByteBuffer)
139139
where S.Element == UInt8
@@ -143,15 +143,15 @@ open class RESPChannelHandler : ChannelDuplexHandler {
143143
out.writeBytes(eol)
144144
}
145145

146-
@inline(__always)
146+
@inlinable
147147
final func encode(simpleString bytes: ByteBuffer, out: inout ByteBuffer) {
148148
var s = bytes
149149
out.writeInteger(UInt8(43)) // +
150150
out.writeBuffer(&s)
151151
out.writeBytes(eol)
152152
}
153153

154-
@inline(__always)
154+
@inlinable
155155
final func encode(bulkString bytes: ByteBuffer?, out: inout ByteBuffer) {
156156
if var s = bytes {
157157
out.writeInteger(UInt8(36)) // $
@@ -165,7 +165,7 @@ open class RESPChannelHandler : ChannelDuplexHandler {
165165
}
166166
}
167167

168-
@inline(__always)
168+
@inlinable
169169
final func encode<S: Collection>(bulkString bytes: S?,
170170
out: inout ByteBuffer)
171171
where S.Element == UInt8
@@ -182,14 +182,14 @@ open class RESPChannelHandler : ChannelDuplexHandler {
182182
}
183183
}
184184

185-
@inline(__always)
185+
@inlinable
186186
final func encode(integer i: Int, out: inout ByteBuffer) {
187187
out.writeInteger(UInt8(58)) // :
188188
out.write(integerAsString : i)
189189
out.writeBytes(eol)
190190
}
191191

192-
@inline(__always)
192+
@inlinable
193193
final func encode(error: RESPError, out: inout ByteBuffer) {
194194
out.writeInteger(UInt8(45)) // -
195195
out.writeString(error.code)
@@ -241,8 +241,10 @@ open class RESPChannelHandler : ChannelDuplexHandler {
241241
}
242242
}
243243

244-
private let eol : ContiguousArray<UInt8> = [ 13, 10 ] // \r\n
245-
private let nilString : ContiguousArray<UInt8> = [ 36, 45, 49, 13, 10 ] // $-1\r\n
244+
@usableFromInline
245+
let eol : ContiguousArray<UInt8> = [ 13, 10 ] // \r\n
246+
@usableFromInline
247+
let nilString : ContiguousArray<UInt8> = [ 36, 45, 49, 13, 10 ] // $-1\r\n
246248
private let nilArray : ContiguousArray<UInt8> = [ 42, 45, 49, 13, 10 ] // *-1\r\n
247249

248250
fileprivate enum ConstantBuffers {

Sources/NIORedis/RESPEncodable.swift

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the swift-nio-redis open source project
44
//
5-
// Copyright (c) 2018 ZeeZide GmbH. and the swift-nio-redis project authors
5+
// Copyright (c) 2018-2021 ZeeZide GmbH. and the swift-nio-redis project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -18,68 +18,58 @@ import struct NIO.ByteBuffer
1818
public protocol RESPEncodable {
1919

2020
func toRESPValue() -> RESPValue
21-
2221
}
2322

2423
extension RESPValue : RESPEncodable {
2524

26-
public func toRESPValue() -> RESPValue {
27-
return self
28-
}
29-
25+
@inlinable
26+
public func toRESPValue() -> RESPValue { return self }
3027
}
3128

3229
extension RESPError : RESPEncodable {
33-
34-
public func toRESPValue() -> RESPValue {
35-
return .error(self)
36-
}
3730

31+
@inlinable
32+
public func toRESPValue() -> RESPValue { return .error(self) }
3833
}
3934

4035
extension Int : RESPEncodable {
4136

42-
public func toRESPValue() -> RESPValue {
43-
return .integer(self)
44-
}
45-
37+
@inlinable
38+
public func toRESPValue() -> RESPValue { return .integer(self) }
4639
}
4740

4841
extension Bool : RESPEncodable {
4942

50-
public func toRESPValue() -> RESPValue {
51-
return .integer(self ? 1 : 0)
52-
}
53-
43+
@inlinable
44+
public func toRESPValue() -> RESPValue { return .integer(self ? 1 : 0) }
5445
}
5546

5647
extension String : RESPEncodable {
5748

49+
@inlinable
5850
public func toRESPValue() -> RESPValue {
5951
return .bulkString(self.utf8.asByteBuffer)
6052
}
61-
6253
}
6354

6455
extension Data : RESPEncodable {
6556

57+
@inlinable
6658
public func toRESPValue() -> RESPValue {
6759
return .bulkString(self.asByteBuffer)
6860
}
69-
7061
}
7162

7263
extension ByteBuffer : RESPEncodable {
73-
74-
public func toRESPValue() -> RESPValue {
75-
return .bulkString(self)
76-
}
77-
64+
65+
@inlinable
66+
public func toRESPValue() -> RESPValue { return .bulkString(self) }
7867
}
7968

8069

8170
extension Array where Element: RESPEncodable {
8271

72+
@inlinable
8373
public func toRESPValue() -> RESPValue {
8474
let arrayOfRedisValues = self.map { $0.toRESPValue() }
8575
return .array(ContiguousArray(arrayOfRedisValues))
@@ -89,6 +79,7 @@ extension Array where Element: RESPEncodable {
8979

9080
extension Array: RESPEncodable {
9181

82+
@inlinable
9283
public func toRESPValue() -> RESPValue {
9384
let array : [ RESPValue ] = self.map { v in
9485
if let rv = (v as? RESPEncodable) {

Sources/NIORedis/RESPParser.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the swift-nio-redis open source project
44
//
5-
// Copyright (c) 2018-2020 ZeeZide GmbH. and the swift-nio-redis project authors
5+
// Copyright (c) 2018-2021 ZeeZide GmbH. and the swift-nio-redis project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -35,7 +35,6 @@ public struct RESPParser {
3535
let count = bp.count
3636
var i = 0
3737

38-
@inline(__always)
3938
func doSkipNL() {
4039
if i >= count {
4140
overflowSkipNL = true
@@ -238,7 +237,6 @@ public struct RESPParser {
238237

239238
// MARK: - Parsing
240239

241-
@inline(__always)
242240
private mutating func pushArrayContext(expectedCount: Int) {
243241
if ctxIndex == ctxCapacity {
244242
for _ in 0..<4 {
@@ -252,7 +250,6 @@ public struct RESPParser {
252250
arrayContextBuffer[ctxIndex].values.reserveCapacity(expectedCount)
253251
}
254252

255-
@inline(__always)
256253
private mutating func decoded(value: RESPValue, yield: Yield) {
257254
if ctxIndex < 0 {
258255
return yield(value)
@@ -313,11 +310,8 @@ public struct RESPParser {
313310
values.reserveCapacity(expectedCount + 1)
314311
}
315312

316-
var isDone : Bool {
317-
@inline(__always) get { return expectedCount <= values.count }
318-
}
313+
var isDone : Bool { return expectedCount <= values.count }
319314

320-
@inline(__always)
321315
mutating func append(value v: RESPValue) -> Bool {
322316
assert(!isDone, "attempt to add to a context which is not TL or done")
323317
values.append(v)
@@ -331,5 +325,4 @@ public struct RESPParser {
331325
private var countValue = 0
332326
private var overflowSkipNL = false
333327
private var overflowBuffer : ByteBuffer?
334-
335328
}

Sources/NIORedis/RESPPipelineSetup.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the swift-nio-redis open source project
44
//
5-
// Copyright (c) 2018-2020 ZeeZide GmbH. and the swift-nio-redis project authors
5+
// Copyright (c) 2018-2021 ZeeZide GmbH. and the swift-nio-redis project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
@@ -17,6 +17,7 @@ import class NIO.EventLoopFuture
1717

1818
public extension ChannelPipeline {
1919

20+
@inlinable
2021
func configureRedisPipeline(first : Bool = false,
2122
name : String = "de.zeezide.nio.RESP")
2223
-> EventLoopFuture<Void>

0 commit comments

Comments
 (0)