diff --git a/Sources/NIO/ByteBuffer-core.swift b/Sources/NIO/ByteBuffer-core.swift index 6216194a66..23d96fd8b9 100644 --- a/Sources/NIO/ByteBuffer-core.swift +++ b/Sources/NIO/ByteBuffer-core.swift @@ -658,10 +658,9 @@ extension StaticString: Collection { public var endIndex: Index { return self.utf8CodeUnitCount } public func index(after i: Index) -> Index { return i + 1 } - public subscript(position: Int) -> StaticString.Element { - get { - return self[position] - } + public subscript(position: Int) -> UInt8 { + precondition(position < self.utf8CodeUnitCount, "index \(position) out of bounds") + return self.utf8Start.advanced(by: position).pointee } } diff --git a/Sources/NIO/CircularBuffer.swift b/Sources/NIO/CircularBuffer.swift index 5525fbcc21..717a2f3c2c 100644 --- a/Sources/NIO/CircularBuffer.swift +++ b/Sources/NIO/CircularBuffer.swift @@ -24,6 +24,11 @@ public protocol AppendableCollection: Collection { /// will automatically expand if more elements than `initialRingCapacity` are stored, it's advantageous to prevent /// expansions from happening frequently. Expansions will always force an allocation and a copy to happen. public struct CircularBuffer: CustomStringConvertible, AppendableCollection { + #if swift(>=4.2) + public typealias RangeType = Range + #else + public typealias RangeType = CountableRange + #endif private var buffer: ContiguousArray /// The index into the buffer of the first item @@ -168,7 +173,7 @@ public struct CircularBuffer: CustomStringConvertible, AppendableCollection { } /// Return all valid indices of the ring. - public var indices: CountableRange { + public var indices: RangeType { return 0..: CustomStringConvertible, AppendableCollection { + #if swift(>=4.2) + public typealias RangeType = Range + #else + public typealias RangeType = CountableRange + #endif + private var buffer: CircularBuffer private var markedIndex: Int = -1 /* negative: nothing marked */ @@ -71,7 +77,7 @@ public struct MarkedCircularBuffer: CustomStringConvertible, AppendableCollec } /// The valid indices into the buffer. - public var indices: CountableRange { + public var indices: RangeType { return self.buffer.indices } diff --git a/Sources/NIOPriorityQueue/Heap.swift b/Sources/NIOPriorityQueue/Heap.swift index bd695fe482..64bcb0946b 100644 --- a/Sources/NIOPriorityQueue/Heap.swift +++ b/Sources/NIOPriorityQueue/Heap.swift @@ -183,6 +183,7 @@ internal struct Heap { @available(*, deprecated, message: "The NIOPriorityQueue module is deprecated and will be removed in the next major release.") extension Heap: CustomDebugStringConvertible { + @available(*, deprecated, message: "The NIOPriorityQueue module is deprecated and will be removed in the next major release.") public var debugDescription: String { guard self.storage.count > 0 else { return "" @@ -266,6 +267,7 @@ extension Heap: Sequence { return self.storage.count } + @available(*, deprecated, message: "The NIOPriorityQueue module is deprecated and will be removed in the next major release.") func makeIterator() -> HeapIterator { return HeapIterator(heap: self) } diff --git a/Sources/NIOPriorityQueue/PriorityQueue.swift b/Sources/NIOPriorityQueue/PriorityQueue.swift index f9fb03f106..3333d4a73d 100644 --- a/Sources/NIOPriorityQueue/PriorityQueue.swift +++ b/Sources/NIOPriorityQueue/PriorityQueue.swift @@ -54,6 +54,7 @@ public struct PriorityQueue { @available(*, deprecated, message: "The NIOPriorityQueue module is deprecated and will be removed in the next major release.") extension PriorityQueue: Equatable { + @available(*, deprecated, message: "The NIOPriorityQueue module is deprecated and will be removed in the next major release.") public static func ==(lhs: PriorityQueue, rhs: PriorityQueue) -> Bool { return lhs.count == rhs.count && lhs.elementsEqual(rhs) } @@ -63,16 +64,21 @@ extension PriorityQueue: Equatable { extension PriorityQueue: Sequence { public struct Iterator: IteratorProtocol { + @available(*, deprecated, message: "The NIOPriorityQueue module is deprecated and will be removed in the next major release.") private var queue: PriorityQueue + + @available(*, deprecated, message: "The NIOPriorityQueue module is deprecated and will be removed in the next major release.") fileprivate init(queue: PriorityQueue) { self.queue = queue } + @available(*, deprecated, message: "The NIOPriorityQueue module is deprecated and will be removed in the next major release.") public mutating func next() -> Element? { return self.queue.pop() } } + @available(*, deprecated, message: "The NIOPriorityQueue module is deprecated and will be removed in the next major release.") public func makeIterator() -> Iterator { return Iterator(queue: self) } @@ -80,6 +86,7 @@ extension PriorityQueue: Sequence { @available(*, deprecated, message: "The NIOPriorityQueue module is deprecated and will be removed in the next major release.") public extension PriorityQueue { + @available(*, deprecated, message: "The NIOPriorityQueue module is deprecated and will be removed in the next major release.") public var count: Int { return self.heap.count } diff --git a/Tests/NIOTests/ByteBufferTest+XCTest.swift b/Tests/NIOTests/ByteBufferTest+XCTest.swift index 254ef53691..c3878e7de1 100644 --- a/Tests/NIOTests/ByteBufferTest+XCTest.swift +++ b/Tests/NIOTests/ByteBufferTest+XCTest.swift @@ -115,6 +115,7 @@ extension ByteBufferTest { ("testLargeSliceBeginMoreThan16MBIsOkay", testLargeSliceBeginMoreThan16MBIsOkay), ("testDiscardReadBytesOnConsumedBuffer", testDiscardReadBytesOnConsumedBuffer), ("testDumpBytesFormat", testDumpBytesFormat), + ("testStaticStringCategorySubscript", testStaticStringCategorySubscript), ] } } diff --git a/Tests/NIOTests/ByteBufferTest.swift b/Tests/NIOTests/ByteBufferTest.swift index bc4f062b38..a73e8f4d51 100644 --- a/Tests/NIOTests/ByteBufferTest.swift +++ b/Tests/NIOTests/ByteBufferTest.swift @@ -1349,6 +1349,12 @@ class ByteBufferTest: XCTestCase { "e0 e1 e2 e3 e4 e5 e6 e7 e8 e9 ea eb ec ed ee ef f0 f1 f2 f3 f4 f5 f6 f7 f8 f9 fa fb fc fd fe ff ]" XCTAssertEqual(expected, actual) } + + func testStaticStringCategorySubscript() throws { + let s: StaticString = "hello" + XCTAssertEqual("h".utf8.first!, s[0]) + XCTAssertEqual("o".utf8.first!, s[4]) + } } private enum AllocationExpectationState: Int {