Skip to content

Commit 3bdc6fd

Browse files
committed
Merge branch 'develop' into main
2 parents c1aff2a + 4ee8423 commit 3bdc6fd

File tree

14 files changed

+156
-240
lines changed

14 files changed

+156
-240
lines changed

.github/workflows/swift.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Build and Test
2+
3+
on:
4+
push:
5+
pull_request:
6+
schedule:
7+
- cron: "5 7 * * 1"
8+
9+
jobs:
10+
linux:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
image:
16+
- swift:5.0.3-xenial
17+
- swift:5.1.5-xenial
18+
- swift:5.2.5-xenial
19+
- swift:5.3.2-xenial
20+
- swift:5.3.2-bionic
21+
container: ${{ matrix.image }}
22+
steps:
23+
- name: Checkout Repository
24+
uses: actions/checkout@v2
25+
- name: Build Swift Debug Package
26+
run: swift build -c debug
27+
- name: Build Swift Release Package
28+
run: swift build -c release
29+
- name: Run Tests
30+
run: swift test
31+
nextstep:
32+
runs-on: macos-latest
33+
steps:
34+
- name: Select latest available Xcode
35+
uses: maxim-lobanov/[email protected]
36+
with:
37+
xcode-version: 12.2
38+
- name: Checkout Repository
39+
uses: actions/checkout@v2
40+
- name: Build Swift Debug Package
41+
run: swift build -c debug
42+
- name: Build Swift Release Package
43+
run: swift build -c release
44+
- name: Run Tests
45+
run: swift test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,5 @@ fastlane/test_output
7070
.build-linux
7171
Package.resolved
7272
.swiftpm
73+
.docker.build
7374

.travis.d/before-install.sh

Lines changed: 0 additions & 22 deletions
This file was deleted.

.travis.d/install.sh

Lines changed: 0 additions & 32 deletions
This file was deleted.

.travis.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

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/ByteBufferExtras.swift

Lines changed: 19 additions & 58 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
@@ -14,69 +14,30 @@
1414

1515
import struct NIO.ByteBuffer
1616

17-
fileprivate extension BinaryInteger {
18-
19-
var numberOfDecimalDigits : Int {
20-
@inline(__always) get {
21-
var value = self
22-
var count = 0
23-
24-
repeat {
25-
value /= 10
26-
count += 1
27-
}
28-
while value != 0
29-
30-
return count
31-
}
32-
}
33-
}
34-
35-
extension ByteBuffer {
17+
public extension ByteBuffer {
18+
// This looks expensive, but isn't. As per @weissi String's store up to 15
19+
// bytes inline, no alloc necessary.
3620

21+
/**
22+
* Write an Integer as an ASCII String.
23+
*/
24+
@inlinable
3725
@discardableResult
38-
public mutating func write<T: SignedInteger>(integerAsString integer: T,
39-
as: T.Type = T.self) -> Int
26+
mutating func write<T: SignedInteger>(integerAsString integer: T,
27+
as: T.Type = T.self) -> Int
4028
{
41-
let bytesWritten = set(integerAsString: integer, at: self.writerIndex)
42-
moveWriterIndex(forwardBy: bytesWritten)
43-
return Int(bytesWritten)
29+
return self.writeString(String(integer, radix: 10))
4430
}
4531

32+
/**
33+
* Set an Integer as an ASCII String.
34+
*/
35+
@inlinable
4636
@discardableResult
47-
public mutating func set<T: SignedInteger>(integerAsString integer: T,
48-
at index: Int,
49-
as: T.Type = T.self) -> Int
37+
mutating func set<T: SignedInteger>(integerAsString integer: T,
38+
at index: Int,
39+
as: T.Type = T.self) -> Int
5040
{
51-
let charCount = integer.numberOfDecimalDigits + (integer < 0 ? 1 : 0)
52-
let avail = capacity - index
53-
54-
if avail < charCount {
55-
reserveCapacity(capacity + (charCount - avail))
56-
}
57-
58-
self.withVeryUnsafeBytes { rbpp in
59-
let mrbpp = UnsafeMutableRawBufferPointer(mutating: rbpp)
60-
let base = mrbpp.baseAddress!.assumingMemoryBound(to: UInt8.self)
61-
.advanced(by: index)
62-
var cursor = base.advanced(by: charCount)
63-
64-
let c0 : T = 48
65-
var negativeAbsoluteValue = integer < 0 ? integer : -integer
66-
repeat {
67-
cursor -= 1
68-
cursor.pointee = UInt8(c0 - (negativeAbsoluteValue % 10))
69-
negativeAbsoluteValue /= 10;
70-
}
71-
while negativeAbsoluteValue != 0
72-
73-
if integer < 0 {
74-
cursor -= 1
75-
cursor.pointee = 45 // -
76-
}
77-
78-
}
79-
80-
return charCount
41+
return self.setString(String(integer, radix: 10), at: index)
8142
}
8243
}

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 {

0 commit comments

Comments
 (0)