Skip to content

Commit 81ca909

Browse files
authored
Faster decoding, thanks to fewer bound checks. (#203)
1 parent 2c49bee commit 81ca909

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+178
-218
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let package = Package(
1313
.library(name: "PostgresNIO", targets: ["PostgresNIO"]),
1414
],
1515
dependencies: [
16-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.33.0"),
16+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.35.0"),
1717
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.14.1"),
1818
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "3.0.0"),
1919
.package(url: "https://github.com/apple/swift-metrics.git", from: "2.0.0"),

Sources/PostgresNIO/Message/PostgresMessage+Authentication.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extension PostgresMessage {
2323
case 10:
2424
var mechanisms: [String] = []
2525
while buffer.readableBytes > 0 {
26-
guard let nextString = buffer.psqlReadNullTerminatedString() else {
26+
guard let nextString = buffer.readNullTerminatedString() else {
2727
throw PostgresError.protocol("Could not parse SASL mechanisms from authentication message")
2828
}
2929
if nextString.isEmpty {
@@ -68,7 +68,7 @@ extension PostgresMessage {
6868
case .saslMechanisms(let mechanisms):
6969
buffer.writeInteger(10, as: Int32.self)
7070
mechanisms.forEach {
71-
buffer.psqlWriteNullTerminatedString($0)
71+
buffer.writeNullTerminatedString($0)
7272
}
7373
case .saslContinue(let challenge):
7474
buffer.writeInteger(11, as: Int32.self)

Sources/PostgresNIO/Message/PostgresMessage+Bind.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ extension PostgresMessage {
3939

4040
/// Serializes this message into a byte buffer.
4141
public func serialize(into buffer: inout ByteBuffer) {
42-
buffer.psqlWriteNullTerminatedString(self.portalName)
43-
buffer.psqlWriteNullTerminatedString(self.statementName)
42+
buffer.writeNullTerminatedString(self.portalName)
43+
buffer.writeNullTerminatedString(self.statementName)
4444

4545
buffer.write(array: self.parameterFormatCodes)
4646
buffer.write(array: self.parameters) {

Sources/PostgresNIO/Message/PostgresMessage+Close.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extension PostgresMessage {
3333
/// Serializes this message into a byte buffer.
3434
public func serialize(into buffer: inout ByteBuffer) throws {
3535
buffer.writeInteger(target.rawValue)
36-
buffer.psqlWriteNullTerminatedString(name)
36+
buffer.writeNullTerminatedString(name)
3737
}
3838
}
3939
}

Sources/PostgresNIO/Message/PostgresMessage+CommandComplete.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extension PostgresMessage {
55
public struct CommandComplete: PostgresMessageType {
66
/// Parses an instance of this message type from a byte buffer.
77
public static func parse(from buffer: inout ByteBuffer) throws -> CommandComplete {
8-
guard let string = buffer.psqlReadNullTerminatedString() else {
8+
guard let string = buffer.readNullTerminatedString() else {
99
throw PostgresError.protocol("Could not parse close response message")
1010
}
1111
return .init(tag: string)

Sources/PostgresNIO/Message/PostgresMessage+Describe.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extension PostgresMessage {
3131
/// Serializes this message into a byte buffer.
3232
public func serialize(into buffer: inout ByteBuffer) {
3333
buffer.writeInteger(command.rawValue)
34-
buffer.psqlWriteNullTerminatedString(name)
34+
buffer.writeNullTerminatedString(name)
3535
}
3636
}
3737
}

Sources/PostgresNIO/Message/PostgresMessage+Error.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extension PostgresMessage {
1111
public static func parse(from buffer: inout ByteBuffer) throws -> Error {
1212
var fields: [Field: String] = [:]
1313
while let field = buffer.readInteger(as: Field.self) {
14-
guard let string = buffer.psqlReadNullTerminatedString() else {
14+
guard let string = buffer.readNullTerminatedString() else {
1515
throw PostgresError.protocol("Could not read error response string.")
1616
}
1717
fields[field] = string

Sources/PostgresNIO/Message/PostgresMessage+Execute.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extension PostgresMessage {
2020

2121
/// Serializes this message into a byte buffer.
2222
public func serialize(into buffer: inout ByteBuffer) {
23-
buffer.psqlWriteNullTerminatedString(portalName)
23+
buffer.writeNullTerminatedString(portalName)
2424
buffer.writeInteger(self.maxRows)
2525
}
2626
}

Sources/PostgresNIO/Message/PostgresMessage+NotificationResponse.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ extension PostgresMessage {
1010
guard let backendPID: Int32 = buffer.readInteger() else {
1111
throw PostgresError.protocol("Invalid NotificationResponse message: unable to read backend PID")
1212
}
13-
guard let channel = buffer.psqlReadNullTerminatedString() else {
13+
guard let channel = buffer.readNullTerminatedString() else {
1414
throw PostgresError.protocol("Invalid NotificationResponse message: unable to read channel")
1515
}
16-
guard let payload = buffer.psqlReadNullTerminatedString() else {
16+
guard let payload = buffer.readNullTerminatedString() else {
1717
throw PostgresError.protocol("Invalid NotificationResponse message: unable to read payload")
1818
}
1919
return .init(backendPID: backendPID, channel: channel, payload: payload)

Sources/PostgresNIO/Message/PostgresMessage+ParameterStatus.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ extension PostgresMessage {
44
public struct ParameterStatus: PostgresMessageType, CustomStringConvertible {
55
/// Parses an instance of this message type from a byte buffer.
66
public static func parse(from buffer: inout ByteBuffer) throws -> ParameterStatus {
7-
guard let parameter = buffer.psqlReadNullTerminatedString() else {
7+
guard let parameter = buffer.readNullTerminatedString() else {
88
throw PostgresError.protocol("Could not read parameter from parameter status message")
99
}
10-
guard let value = buffer.psqlReadNullTerminatedString() else {
10+
guard let value = buffer.readNullTerminatedString() else {
1111
throw PostgresError.protocol("Could not read value from parameter status message")
1212
}
1313
return .init(parameter: parameter, value: value)

0 commit comments

Comments
 (0)