Skip to content

Commit 25343db

Browse files
authored
Merge branch 'main' into openbsd
2 parents 6c97c72 + 843c8cf commit 25343db

File tree

14 files changed

+1092
-193
lines changed

14 files changed

+1092
-193
lines changed

.github/workflows/benchmarks.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ on:
7676
description: "Environment variables for Linux jobs as JSON (e.g., '{\"DEBUG\":\"1\",\"LOG_LEVEL\":\"info\"}')."
7777
default: "{}"
7878

79-
permissions:
80-
contents: read
79+
minimum_swift_version:
80+
type: string
81+
description: "Minimum Swift version to include in the matrix. Leave empty for auto-detection from Package.swift, specify a version like '6.0' to override, or set to 'none' to disable filtering."
82+
default: ""
8183

8284
jobs:
8385
construct-matrix:
@@ -104,6 +106,7 @@ jobs:
104106
env:
105107
MATRIX_LINUX_COMMAND: "curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/check_benchmark_thresholds.sh | BENCHMARK_PACKAGE_PATH=${{ inputs.benchmark_package_path }} bash"
106108
MATRIX_LINUX_SETUP_COMMAND: "swift --version && apt-get update -y -q && apt-get install -y -q curl libjemalloc-dev && git config --global --add safe.directory /$(basename ${{ github.workspace }})"
109+
MATRIX_MIN_SWIFT_VERSION: ${{ inputs.minimum_swift_version }}
107110
MATRIX_LINUX_5_9_ENABLED: ${{ inputs.linux_5_9_enabled }}
108111
MATRIX_LINUX_5_10_ENABLED: ${{ inputs.linux_5_10_enabled }}
109112
MATRIX_LINUX_6_0_ENABLED: ${{ inputs.linux_6_0_enabled }}

.github/workflows/cxx_interop.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ on:
7373
description: "Environment variables for Windows jobs as JSON (e.g., '{\"DEBUG\":\"1\",\"LOG_LEVEL\":\"info\"}')."
7474
default: "{}"
7575

76-
permissions:
77-
contents: read
76+
minimum_swift_version:
77+
type: string
78+
description: "Minimum Swift version to include in the matrix. Leave empty for auto-detection from Package.swift, specify a version like '6.0' to override, or set to 'none' to disable filtering."
79+
default: ""
7880

7981
jobs:
8082
construct-matrix:
@@ -107,6 +109,7 @@ jobs:
107109
env:
108110
MATRIX_LINUX_COMMAND: "curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/check-cxx-interop-compatibility.sh | bash"
109111
MATRIX_LINUX_SETUP_COMMAND: "swift --version && apt-get update -y -q && apt-get install -y -q curl jq"
112+
MATRIX_MIN_SWIFT_VERSION: ${{ inputs.minimum_swift_version }}
110113
MATRIX_LINUX_5_9_ENABLED: ${{ inputs.linux_5_9_enabled }}
111114
MATRIX_LINUX_5_10_ENABLED: ${{ inputs.linux_5_10_enabled }}
112115
MATRIX_LINUX_6_0_ENABLED: ${{ inputs.linux_6_0_enabled }}

.github/workflows/release_builds.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ on:
105105
description: "Environment variables for Windows jobs as JSON (e.g., '{\"DEBUG\":\"1\",\"LOG_LEVEL\":\"info\"}')."
106106
default: "{}"
107107

108-
permissions:
109-
contents: read
108+
minimum_swift_version:
109+
type: string
110+
description: "Minimum Swift version to include in the matrix. Leave empty for auto-detection from Package.swift, specify a version like '6.0' to override, or set to 'none' to disable filtering."
111+
default: ""
110112

111113
jobs:
112114
construct-matrix:
@@ -139,6 +141,7 @@ jobs:
139141
env:
140142
MATRIX_LINUX_SETUP_COMMAND: "swift --version"
141143
MATRIX_LINUX_COMMAND: "swift build -c release"
144+
MATRIX_MIN_SWIFT_VERSION: ${{ inputs.minimum_swift_version }}
142145
MATRIX_LINUX_5_10_ENABLED: ${{ inputs.linux_5_10_enabled }}
143146
MATRIX_LINUX_5_10_COMMAND_ARGUMENTS: ${{ inputs.linux_5_10_arguments_override }}
144147
MATRIX_LINUX_6_0_ENABLED: ${{ inputs.linux_6_0_enabled }}

.github/workflows/unit_tests.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ on:
145145
description: "Environment variables for Windows jobs as JSON (e.g., '{\"DEBUG\":\"1\",\"LOG_LEVEL\":\"info\"}')."
146146
default: "{}"
147147

148+
minimum_swift_version:
149+
type: string
150+
description: "Minimum Swift version to include in the matrix. Leave empty for auto-detection from Package.swift, specify a version like '6.0' to override, or set to 'none' to disable filtering."
151+
default: ""
152+
148153
jobs:
149154
construct-matrix:
150155
name: Construct unit test matrix
@@ -178,6 +183,7 @@ jobs:
178183
env:
179184
MATRIX_LINUX_SETUP_COMMAND: "swift --version"
180185
MATRIX_LINUX_COMMAND: "swift test"
186+
MATRIX_MIN_SWIFT_VERSION: ${{ inputs.minimum_swift_version }}
181187
MATRIX_LINUX_5_9_ENABLED: ${{ inputs.linux_5_9_enabled }}
182188
MATRIX_LINUX_5_9_COMMAND_ARGUMENTS: ${{ inputs.linux_5_9_arguments_override }}
183189
MATRIX_LINUX_5_10_ENABLED: ${{ inputs.linux_5_10_enabled }}

Sources/NIOCore/ByteBuffer-views.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,22 @@ extension ByteBufferView: RangeReplaceableCollection {
259259
try ptr.firstIndex(where: predicate).map { $0 + self._range.lowerBound }
260260
}
261261
}
262+
263+
/// Returns the index of the last byte that matches the given predicate.
264+
///
265+
/// - Parameter predicate: A closure that takes a byte as its argument
266+
/// and returns a Boolean value that indicates whether the passed byte
267+
/// represents a match.
268+
/// - Returns: The index of the last byte in the collection that matches
269+
/// `predicate`, or `nil` if no bytes match.
270+
///
271+
/// - Complexity: O(*n*), where *n* is the length of the collection.
272+
@inlinable
273+
public func lastIndex(where predicate: (UInt8) throws -> Bool) rethrows -> Index? {
274+
try self.withUnsafeBytes { ptr in
275+
try ptr.lastIndex(where: predicate).map { $0 + self._range.lowerBound }
276+
}
277+
}
262278
}
263279

264280
extension ByteBuffer {

Sources/NIOCore/NIODecodedAsyncSequence.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ extension NIODecodedAsyncSequence: AsyncSequence {
9595
public struct AsyncIterator: AsyncIteratorProtocol {
9696
@usableFromInline
9797
enum State: Sendable {
98-
case readingFromBuffer
99-
case readLastChunkFromBuffer
98+
case canReadFromBaseIterator
99+
case baseIteratorIsExhausted
100100
case finishedDecoding
101101
}
102102

@@ -114,7 +114,7 @@ extension NIODecodedAsyncSequence: AsyncSequence {
114114
base.decoder,
115115
maximumBufferSize: base.maximumBufferSize
116116
)
117-
self.state = .readingFromBuffer
117+
self.state = .canReadFromBaseIterator
118118
}
119119

120120
/// Retrieve the next element from the ``NIODecodedAsyncSequence``.
@@ -127,7 +127,7 @@ extension NIODecodedAsyncSequence: AsyncSequence {
127127
switch self.state {
128128
case .finishedDecoding:
129129
return nil
130-
case .readingFromBuffer:
130+
case .canReadFromBaseIterator:
131131
let (decoded, ended) = try self.processor.decodeNext(
132132
decodeMode: .normal,
133133
seenEOF: false
@@ -144,11 +144,11 @@ extension NIODecodedAsyncSequence: AsyncSequence {
144144
// Read more data into the buffer so we can decode more messages
145145
guard let nextBuffer = try await self.baseIterator.next() else {
146146
// Ran out of data to read.
147-
self.state = .readLastChunkFromBuffer
147+
self.state = .baseIteratorIsExhausted
148148
continue
149149
}
150150
self.processor.append(nextBuffer)
151-
case .readLastChunkFromBuffer:
151+
case .baseIteratorIsExhausted:
152152
let (decoded, ended) = try self.processor.decodeNext(
153153
decodeMode: .last,
154154
seenEOF: true
@@ -175,7 +175,7 @@ extension NIODecodedAsyncSequence: AsyncSequence {
175175
switch self.state {
176176
case .finishedDecoding:
177177
return nil
178-
case .readingFromBuffer:
178+
case .canReadFromBaseIterator:
179179
let (decoded, ended) = try self.processor.decodeNext(
180180
decodeMode: .normal,
181181
seenEOF: false
@@ -192,11 +192,11 @@ extension NIODecodedAsyncSequence: AsyncSequence {
192192
// Read more data into the buffer so we can decode more messages
193193
guard let nextBuffer = try await self.baseIterator.next(isolation: actor) else {
194194
// Ran out of data to read.
195-
self.state = .readLastChunkFromBuffer
195+
self.state = .baseIteratorIsExhausted
196196
continue
197197
}
198198
self.processor.append(nextBuffer)
199-
case .readLastChunkFromBuffer:
199+
case .baseIteratorIsExhausted:
200200
let (decoded, ended) = try self.processor.decodeNext(
201201
decodeMode: .last,
202202
seenEOF: true

0 commit comments

Comments
 (0)