Skip to content

Commit 9011f20

Browse files
committed
Reduce size of RESPValue from 49 to 25
By backing RESPError fields in a class. This way it isn't taking up storage in each and every RESPValue. 25 is still > 24 though :-) (thanks to @weissi for the suggestion)
1 parent 5b78b9d commit 9011f20

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

Sources/NIORedis/RESPValue.swift

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@
1515
import NIO
1616
import Foundation
1717

18-
public struct RESPError : Error {
19-
let code : String
20-
let message : String
21-
22-
public init(code: String = "ERR", message: String = "Generic Error") {
23-
self.code = code
24-
self.message = message
25-
}
26-
}
27-
2818
public enum RESPValue {
2919
case simpleString(ByteBuffer)
3020
case bulkString (ByteBuffer?)
@@ -33,6 +23,25 @@ public enum RESPValue {
3323
case error (RESPError)
3424
}
3525

26+
public struct RESPError : Error {
27+
28+
public init(code: String = "ERR", message: String = "Generic Error") {
29+
_storage = _Storage(code: code, message: message)
30+
}
31+
32+
public var code : String { return _storage.code }
33+
public var message : String { return _storage.message }
34+
35+
private final class _Storage {
36+
let code : String
37+
let message : String
38+
public init(code: String, message: String) {
39+
self.code = code
40+
self.message = message
41+
}
42+
}
43+
private let _storage : _Storage
44+
}
3645

3746
// MARK: - Initializers
3847

0 commit comments

Comments
 (0)